blob: 35cf23ba2b1dbc3c5a049086245ea0eaf1ed1411
1 | |
2 | /* |
3 | #include <media/stagefright/foundation/ADebug.h> |
4 | #include <media/stagefright/DataSource.h> |
5 | #include <media/stagefright/MediaBufferGroup.h> |
6 | #include <media/stagefright/MediaDefs.h> |
7 | #include <media/stagefright/MediaErrors.h> |
8 | #include <media/stagefright/MediaSource.h> |
9 | #include <media/stagefright/MetaData.h> |
10 | #include <utils/String8.h> |
11 | #include <cutils/bitops.h> |
12 | */ |
13 | #include "MediaSource.h" |
14 | #include "DataSource.h" |
15 | #include "MediaBufferGroup.h" |
16 | #include "MetaData.h" |
17 | namespace android |
18 | { |
19 | |
20 | |
21 | #define DSPshort short |
22 | #define DSPerr short |
23 | #define DSPushort unsigned short /*!< DSP unsigned integer */ |
24 | #define GBL_BYTESPERWRD 2 /*!< Bytes per packed word */ |
25 | #define GBL_BITSPERWRD (GBL_BYTESPERWRD*8) /*!< Bytes per packed word */ |
26 | #define GBL_SYNCWRD ((DSPshort)0x0b77) /*!< AC-3 frame sync word */ |
27 | #define GBL_MAXFSCOD 3 /*!< Number of defined sample rates */ |
28 | #define GBL_MAXDDDATARATE 38 /*!< Number of defined data rates */ |
29 | #define BSI_BSID_STD 8 /*!< Standard ATSC A/52 bit-stream ID */ |
30 | #define BSI_ISDD(bsid) ((bsid) <= BSI_BSID_STD) |
31 | #define GBL_MAXCHANCFGS 8 /*!< Maximum number of channel configs */ |
32 | #define BSI_BSID_AXE 16 /*!< Annex E bitstream ID */ |
33 | #define BSI_ISDDP(bsid) ((bsid) <= BSI_BSID_AXE && (bsid) > 10) |
34 | #define BSI_BSID_BITOFFSET 40 /*!< Used to skip ahead to bit-stream ID */ |
35 | #define PTR_HEAD_SIZE 20 |
36 | |
37 | |
38 | /*! \brief Bit Stream Operations module decode-side state variable structure */ |
39 | typedef struct { |
40 | DSPshort *p_pkbuf; /*!< Pointer to bitstream buffer */ |
41 | DSPshort pkbitptr; /*!< Bit count within bitstream word */ |
42 | DSPshort pkdata; /*!< Current bitstream word */ |
43 | #if defined(DEBUG) |
44 | const DSPshort *p_start_pkbuf; /*!< Pointer to beginning of bitstream buffer */ |
45 | #endif /* defined(DEBUG) */ |
46 | } BSOD_BSTRM; |
47 | |
48 | |
49 | const DSPshort gbl_chanary[GBL_MAXCHANCFGS] = { 2, 1, 2, 3, 3, 4, 4, 5 }; |
50 | /* audio coding modes */ |
51 | enum { GBL_MODE11 = 0, GBL_MODE_RSVD = 0, GBL_MODE10, GBL_MODE20, |
52 | GBL_MODE30, GBL_MODE21, GBL_MODE31, GBL_MODE22, GBL_MODE32 |
53 | }; |
54 | |
55 | const DSPushort gbl_msktab[] = { |
56 | 0x0000, 0x8000, 0xc000, 0xe000, |
57 | 0xf000, 0xf800, 0xfc00, 0xfe00, |
58 | 0xff00, 0xff80, 0xffc0, 0xffe0, |
59 | 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff |
60 | }; |
61 | |
62 | |
63 | /*! Words per frame table based on sample rate and data rate codes */ |
64 | const DSPshort gbl_frmsizetab[GBL_MAXFSCOD][GBL_MAXDDDATARATE] = { |
65 | /* 48kHz */ |
66 | { |
67 | 64, 64, 80, 80, 96, 96, 112, 112, |
68 | 128, 128, 160, 160, 192, 192, 224, 224, |
69 | 256, 256, 320, 320, 384, 384, 448, 448, |
70 | 512, 512, 640, 640, 768, 768, 896, 896, |
71 | 1024, 1024, 1152, 1152, 1280, 1280 |
72 | }, |
73 | /* 44.1kHz */ |
74 | { |
75 | 69, 70, 87, 88, 104, 105, 121, 122, |
76 | 139, 140, 174, 175, 208, 209, 243, 244, |
77 | 278, 279, 348, 349, 417, 418, 487, 488, |
78 | 557, 558, 696, 697, 835, 836, 975, 976, |
79 | 1114, 1115, 1253, 1254, 1393, 1394 |
80 | }, |
81 | /* 32kHz */ |
82 | { |
83 | 96, 96, 120, 120, 144, 144, 168, 168, |
84 | 192, 192, 240, 240, 288, 288, 336, 336, |
85 | 384, 384, 480, 480, 576, 576, 672, 672, |
86 | 768, 768, 960, 960, 1152, 1152, 1344, 1344, |
87 | 1536, 1536, 1728, 1728, 1920, 1920 |
88 | } |
89 | }; |
90 | |
91 | |
92 | |
93 | typedef int (*fp_read_buffer)(unsigned char *, int); |
94 | struct AudioMediaSource : public MediaSource { |
95 | AudioMediaSource(void *read_buffer); |
96 | virtual status_t start(MetaData *params = NULL); |
97 | virtual status_t stop(); |
98 | virtual sp<MetaData> getFormat(); |
99 | virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL); |
100 | int GetReadedBytes(); |
101 | int SetReadedBytes(int size); |
102 | int MediaSourceRead_buffer(unsigned char *buffer, int size); |
103 | fp_read_buffer fpread_buffer; |
104 | |
105 | //---------------------------------------- |
106 | DSPerr bsod_init(DSPshort * p_pkbuf, DSPshort pkbitptr, BSOD_BSTRM *p_bstrm); |
107 | DSPerr bsod_unprj(BSOD_BSTRM *p_bstrm, DSPshort *p_data, DSPshort numbits); |
108 | int Get_ChNum_DD(void *buf); |
109 | int Get_ChNum_DDP(void *buf); |
110 | DSPerr bsod_skip(BSOD_BSTRM *p_bstrm, DSPshort numbits); |
111 | DSPerr bsid_getbsid(BSOD_BSTRM *p_inbstrm, DSPshort *p_bsid); |
112 | int Get_ChNum_AC3_Frame(void *buf); |
113 | //--------------------------------------- |
114 | |
115 | int sample_rate; |
116 | int ChNum; |
117 | int frame_size; |
118 | int64_t bytes_readed_sum_pre; |
119 | int64_t bytes_readed_sum; |
120 | int *pStop_ReadBuf_Flag; |
121 | protected: |
122 | virtual ~AudioMediaSource(); |
123 | |
124 | private: |
125 | bool mStarted; |
126 | sp<DataSource> mDataSource; |
127 | sp<MetaData> mMeta; |
128 | MediaBufferGroup *mGroup; |
129 | int64_t mCurrentTimeUs; |
130 | int mBytesReaded; |
131 | |
132 | AudioMediaSource(const AudioMediaSource &); |
133 | AudioMediaSource &operator=(const AudioMediaSource &); |
134 | }; |
135 | |
136 | |
137 | } |
138 |