M4PCMR_CoreReader.h revision 7c9d8018755adf1857571125ba1b3598c96ea506
1/*
2 * Copyright (C) 2004-2011 NXP Software
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 ************************************************************************
19 * @file    M4WAV_WavReader.h
20 * @brief   WAV Reader declarations
21 * @note    This file implements functions of the WAV reader
22 ************************************************************************
23*/
24
25#include "M4OSA_CoreID.h"
26#include "M4OSA_Types.h"
27#include "M4OSA_Memory.h"
28#include "M4OSA_FileReader.h"
29#include "M4SYS_AccessUnit.h"
30#include "M4TOOL_VersionInfo.h"
31
32
33#define M4PCMC_ERR_PCM_NOT_COMPLIANT    M4OSA_ERR_CREATE(M4_ERR, M4WAV_COMMON,0x000001)
34#define M4PCMC_ERR_PCM_NO_SPACE_AVAIL   M4OSA_ERR_CREATE(M4_ERR, M4WAV_COMMON,0x000002)
35#define M4PCMC_ERR_PCM_NOT_SUPPORTED    M4OSA_ERR_CREATE(M4_ERR, M4WAV_COMMON,0x000003)
36
37#define M4PCMC_WAR_END_OF_STREAM        M4OSA_ERR_CREATE(M4_WAR, M4WAV_COMMON ,0x000001)
38
39/**
40 ************************************************************************
41 * structure    M4WAVC_DecoderSpecificInfo
42 * @brief       This structure defines the decoder Specific informations
43 * @note        This structure is used by the WAV reader to store all
44 *              decoder specific informations:
45 *              - Sample Frequency
46 *              - Average Bytes per second
47 *              - Number of channels (1 or 2)
48 *              - Number of bits per sample (8 or 16)
49 ************************************************************************
50*/
51typedef struct {
52    M4OSA_UInt32    SampleFrequency;
53    M4OSA_UInt32    AvgBytesPerSec;
54    M4OSA_UInt32    DataLength;
55    M4OSA_UInt16    nbChannels;
56    M4OSA_UInt16    BitsPerSample;
57} M4PCMC_DecoderSpecificInfo;
58
59/**
60 ************************************************************************
61 * enum     M4WAVR_State
62 * @brief   This enum defines the WAV Reader States
63 * @note    The state automaton is documented separately
64 *          consult the design specification for details
65 ************************************************************************
66*/
67typedef enum {
68    M4PCMR_kInit    = 0x0000,
69    M4PCMR_kOpening = 0x0100,
70    M4PCMR_kOpening_streamRetrieved = 0x0101,
71    M4PCMR_kReading = 0x0200,
72    M4PCMR_kReading_nextAU  = 0x0201,
73    M4PCMR_kClosed  = 0x0300
74} M4PCMR_State;
75
76/**
77 ************************************************************************
78 * enum     M4WAVR_OptionID
79 * @brief   This enum defines the WAV Reader options
80 * @note    Only one option is available:
81 *          - M4WAVR_kPCMblockSize: sets the size of the PCM block to read
82 *            from WAV file
83 ************************************************************************
84*/
85typedef enum {
86    M4PCMR_kPCMblockSize    = M4OSA_OPTION_ID_CREATE(M4_READ, M4WAV_READER, 0x01)
87} M4PCMR_OptionID;
88
89/**
90 ************************************************************************
91 * structure    M4WAVR_Context
92 * @brief       This structure defines the WAV Reader context
93 * @note        This structure is used for all WAV Reader calls to store
94 *              the context
95 ************************************************************************
96*/
97typedef struct {
98    M4OSA_MemAddr32             m_pDecoderSpecInfo;/**< Pointer to the decoder specific info
99                                                        structure contained in pStreamDesc
100                                                        (only used to free...) */
101    M4OSA_FileReadPointer*      m_pFileReadFunc;/**< The OSAL set of pointer to function for
102                                                         file management */
103    M4OSA_Context               m_fileContext;  /**< The context needed by OSAL to manage File */
104    M4PCMC_DecoderSpecificInfo  m_decoderConfig;/**< Specific configuration for decoder */
105    M4PCMR_State                m_state;        /**< state of the wav reader */
106    M4PCMR_State                m_microState;   /**< state of the read wav stream */
107    M4OSA_UInt32                m_blockSize;    /**< Size of the read block */
108    M4OSA_UInt32                m_offset;       /**< Offset of the PCM read (i.e m_offset of the
109                                                        file without wav header) */
110    M4OSA_MemAddr32             m_pAuBuffer;    /**< Re-used buffer for AU content storage */
111    M4OSA_FilePosition          m_dataStartOffset;/**< offset of the pcm data beginning into
112                                                         the file */
113} M4PCMR_Context;
114
115/*************************************************************************
116 *
117 *  Prototypes of all WAV reader functions
118 *
119 ************************************************************************/
120M4OSA_ERR M4PCMR_openRead(M4OSA_Context* pContext, M4OSA_Void* pUrl,
121                             M4OSA_FileReadPointer* pFileFunction);
122M4OSA_ERR M4PCMR_getNextStream(M4OSA_Context context, M4SYS_StreamDescription* pStreamDesc);
123M4OSA_ERR M4PCMR_startReading(M4OSA_Context context, M4SYS_StreamID* pStreamIDs);
124M4OSA_ERR M4PCMR_nextAU(M4OSA_Context context, M4SYS_StreamID streamID, M4SYS_AccessUnit* pAU);
125M4OSA_ERR M4PCMR_freeAU(M4OSA_Context context, M4SYS_StreamID streamID, M4SYS_AccessUnit* pAU);
126M4OSA_ERR M4PCMR_seek(M4OSA_Context context, M4SYS_StreamID* pStreamID, M4OSA_Time time,
127                         M4SYS_SeekAccessMode seekAccessMode, M4OSA_Time* pObtainCTS);
128M4OSA_ERR M4PCMR_closeRead(M4OSA_Context context);
129M4OSA_ERR M4PCMR_getOption(M4OSA_Context context, M4PCMR_OptionID optionID,
130                              M4OSA_DataOption* pValue);
131M4OSA_ERR M4PCMR_setOption(M4OSA_Context context, M4PCMR_OptionID optionID,
132                              M4OSA_DataOption Value);
133M4OSA_ERR M4PCMR_getVersion(M4_VersionInfo *pVersion);
134