/*===========================================================================

FILE: OEMRegistry.c

SERVICES: OEM Registry related implementation.

DESCRIPTION
   This file implements IMedia for BREW MultiMedia format. All 
   media formats like MIDI, MP3, QCP must be derived from this class.

PUBLIC CLASSES:  Not Applicable

INITIALIZATION AND SEQUENCING REQUIREMENTS:  Not Applicable

        Copyright © 1999-2002 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
===========================================================================*/
/*===========================================================================

                     INCLUDE FILES FOR MODULE

===========================================================================*/
#include "OEMFeatures.h"
#include "OEMRegistry.h"

#if defined(FEATURE_BREW_MULTIMEDIA)
#include "OEMMedia.h"
#endif // defined(FEATURE_BREW_MULTIMEDIA)

/*======================================================================= 
Function: OEMRegistry_DetectType

Description: 
   Given data in a buffer or the name of an object, this function detects 
   the MIME type. 
   
   This function is typically used to get the handler associated with the data type. 
   For example, if the data represents standard MIDI format, then this 
   function returns the MIME "audio/mid". Using the MIME type, you can query 
   Shell registry to obtain the handler (Class ID) of type AEECLSID_MEDIA.

Prototype:

   int OEMRegistry_DetectType(IShell * po, const void * cpBuf, uint32 * pdwSize, const char * cpszName, const char ** pcpszMIME);

Parameters:
   po [in]:          Pointer to the IShell object
   cpBuf [in]:       Buffer containing the data whose type needs to be determined
   pdwSize [in/out]: On input: Size of data in pBuf, unless pBuf is NULL, then ignored
                     On output: number of additional data bytes needed to perform type detection
   cpszName [in]:    Name of the object whose type needs to be determined (may be null, if unknown).
   pcpszMIME [out]:  MIME string returned to caller, on return, filled with a pointer to a constant string (do not free)

Return Value: 
   SUCCESS:    Data type is detected and MIME is returned
   ENOTYPE:    There is no type associated with this data
   EBADPARM:   Wrong input data (parameter(s))
   ENEEDMORE:  Need more data to perform type detection. *pdwSize contains the the required
               number of additional bytes.
   EUNSUPPORTED: Type detection for the specified input is not supported

Comments: None
Side Effects: None
See Also: None
========================================================================*/
int OEMRegistry_DetectType(const void * cpBuf, uint32 * pdwSize, const char * cpszName, const char ** pcpszMIME)
{
   int      nRet;
   uint32   dwMaxBytes = 0; // the max number of additional bytes needed to enable type detection.

   if (cpszName && !cpBuf)
      return EUNSUPPORTED;

   if (cpBuf && !pdwSize)
      return EBADPARM;

   // Check if data is IMedia type...
#if defined(FEATURE_BREW_MULTIMEDIA)
   nRet = OEMMedia_DetectType(cpBuf, pdwSize, cpszName, pcpszMIME);
   if (nRet == ENEEDMORE && *pdwSize > dwMaxBytes)
      dwMaxBytes = *pdwSize;
   else
      return nRet;
#endif // defined(FEATURE_BREW_MULTIMEDIA)

   //
   // Implement other type detections here...
   //

   *pdwSize = dwMaxBytes;
   return ENEEDMORE;
}
