blob: b5d0160f456660576d01de607f5d9c1eccd24209
1 | #ifndef MEDIA_DDPMEDIASOURCE_H_ |
2 | #define MEDIA_DDPMEDIASOURCE_H_ |
3 | |
4 | #include "MediaSource.h" |
5 | #include "DataSource.h" |
6 | #include "MediaBufferGroup.h" |
7 | #include "MetaData.h" |
8 | #include "audio_mediasource.h" |
9 | |
10 | namespace android { |
11 | |
12 | #define DDPshort short |
13 | #define DDPerr short |
14 | #define DDPushort unsigned short |
15 | #define BYTESPERWRD 2 |
16 | #define BITSPERWRD (BYTESPERWRD*8) |
17 | #define SYNCWRD ((DDPshort)0x0b77) |
18 | #define MAXFSCOD 3 |
19 | #define MAXDDDATARATE 38 |
20 | #define BS_STD 8 |
21 | #define ISDD(bsid) ((bsid) <= BS_STD) |
22 | #define MAXCHANCFGS 8 |
23 | #define BS_AXE 16 |
24 | #define ISDDP(bsid) ((bsid) <= BS_AXE && (bsid) > 10) |
25 | #define BS_BITOFFSET 40 |
26 | #define PTR_HEAD_SIZE 7 //20 |
27 | #define FRAME_RECORD_NUM 40 |
28 | typedef struct { |
29 | DDPshort *buf; |
30 | DDPshort bitptr; |
31 | DDPshort data; |
32 | } DDP_BSTRM; |
33 | |
34 | typedef struct { |
35 | unsigned char rawbuf[6144]; |
36 | int len; |
37 | } BUF_T; |
38 | |
39 | const DDPshort chanary[MAXCHANCFGS] = { 2, 1, 2, 3, 3, 4, 4, 5 }; |
40 | enum { MODE11 = 0, MODE_RSVD = 0, MODE10, MODE20, |
41 | MODE30, MODE21, MODE31, MODE22, MODE32 |
42 | }; |
43 | |
44 | const DDPushort msktab[] = { |
45 | 0x0000, 0x8000, 0xc000, 0xe000, |
46 | 0xf000, 0xf800, 0xfc00, 0xfe00, |
47 | 0xff00, 0xff80, 0xffc0, 0xffe0, |
48 | 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff |
49 | }; |
50 | |
51 | const DDPshort frmsizetab[MAXFSCOD][MAXDDDATARATE] = { |
52 | /* 48kHz */ |
53 | { |
54 | 64, 64, 80, 80, 96, 96, 112, 112, |
55 | 128, 128, 160, 160, 192, 192, 224, 224, |
56 | 256, 256, 320, 320, 384, 384, 448, 448, |
57 | 512, 512, 640, 640, 768, 768, 896, 896, |
58 | 1024, 1024, 1152, 1152, 1280, 1280}, |
59 | /* 44.1kHz */ |
60 | { |
61 | 69, 70, 87, 88, 104, 105, 121, 122, |
62 | 139, 140, 174, 175, 208, 209, 243, 244, |
63 | 278, 279, 348, 349, 417, 418, 487, 488, |
64 | 557, 558, 696, 697, 835, 836, 975, 976, |
65 | 1114, 1115, 1253, 1254, 1393, 1394}, |
66 | /* 32kHz */ |
67 | { |
68 | 96, 96, 120, 120, 144, 144, 168, 168, |
69 | 192, 192, 240, 240, 288, 288, 336, 336, |
70 | 384, 384, 480, 480, 576, 576, 672, 672, |
71 | 768, 768, 960, 960, 1152, 1152, 1344, 1344, |
72 | 1536, 1536, 1728, 1728, 1920, 1920} |
73 | }; |
74 | |
75 | typedef int (*fp_read_buffer) (unsigned char *, int); |
76 | |
77 | class DDP_MediaSource:public AudioMediaSource { |
78 | public: |
79 | DDP_MediaSource(void *read_buffer); |
80 | |
81 | status_t start(MetaData * params = NULL); |
82 | status_t stop(); |
83 | sp < MetaData > getFormat(); |
84 | status_t read(MediaBuffer ** buffer, |
85 | const ReadOptions * options = NULL); |
86 | |
87 | int GetReadedBytes(); |
88 | int GetSampleRate(); |
89 | int GetChNum(); |
90 | virtual int GetChNumOriginal(); |
91 | int *Get_pStop_ReadBuf_Flag(); |
92 | int Set_pStop_ReadBuf_Flag(int *pStop); |
93 | |
94 | int SetReadedBytes(int size); |
95 | int MediaSourceRead_buffer(unsigned char *buffer, int size); |
96 | |
97 | fp_read_buffer fpread_buffer; |
98 | |
99 | //---------------------------------------- |
100 | DDPerr ddbs_init(DDPshort * buf, DDPshort bitptr, |
101 | DDP_BSTRM * p_bstrm); |
102 | DDPerr ddbs_unprj(DDP_BSTRM * p_bstrm, DDPshort * p_data, |
103 | DDPshort numbits); |
104 | int Get_ChNum_DD(void *buf); |
105 | int Get_ChNum_DDP(void *buf); |
106 | DDPerr ddbs_skip(DDP_BSTRM * p_bstrm, DDPshort numbits); |
107 | DDPerr ddbs_getbsid(DDP_BSTRM * p_inbstrm, DDPshort * p_bsid); |
108 | int Get_ChNum_AC3_Frame(void *buf); |
109 | int get_frame_size(void); |
110 | void store_frame_size(int lastFrameLen); |
111 | //--------------------------------------- |
112 | |
113 | int sample_rate; |
114 | int ChNum; |
115 | int frame_size; |
116 | BUF_T frame; |
117 | int64_t bytes_readed_sum_pre; |
118 | int64_t bytes_readed_sum; |
119 | int extractor_cost_bytes; |
120 | int extractor_cost_bytes_last; |
121 | int *pStop_ReadBuf_Flag; |
122 | int ChNumOriginal; |
123 | int frame_length_his[FRAME_RECORD_NUM]; |
124 | protected: |
125 | virtual ~ DDP_MediaSource(); |
126 | |
127 | private: |
128 | bool mStarted; |
129 | sp < DataSource > mDataSource; |
130 | sp < MetaData > mMeta; |
131 | MediaBufferGroup *mGroup; |
132 | int64_t mCurrentTimeUs; |
133 | int mBytesReaded; |
134 | |
135 | DDP_MediaSource(const DDP_MediaSource &); |
136 | DDP_MediaSource & operator=(const DDP_MediaSource &); |
137 | }; |
138 | |
139 | } |
140 | |
141 | #endif |
142 |