blob: 685ae09a11fe87f6328524ec86b1a02d57cf8b43
1 | #ifndef MEDIA_MP3MEDIASOURCE_H_ |
2 | #define MEDIA_MP3MEDIASOURCE_H_ |
3 | |
4 | #include "MediaSource.h" |
5 | #include "DataSource.h" |
6 | #include "MediaBufferGroup.h" |
7 | #include "MetaData.h" |
8 | #include "audio_mediasource.h" |
9 | #include "../audio-dec.h" |
10 | |
11 | namespace android |
12 | { |
13 | |
14 | typedef int (*fp_read_buffer)(unsigned char *, int); |
15 | |
16 | class MP3_MediaSource : public AudioMediaSource |
17 | { |
18 | public: |
19 | MP3_MediaSource(void *read_buffer, aml_audio_dec_t *audec, int *exit); |
20 | |
21 | status_t start(MetaData *params = NULL); |
22 | status_t stop(); |
23 | sp<MetaData> getFormat(); |
24 | status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL); |
25 | |
26 | int GetReadedBytes(); |
27 | int GetSampleRate(); |
28 | int GetChNum(); |
29 | int* Get_pStop_ReadBuf_Flag(); |
30 | int Set_pStop_ReadBuf_Flag(int *pStop); |
31 | |
32 | int set_MP3_MetaData(aml_audio_dec_t *audec); |
33 | int MediaSourceRead_buffer(unsigned char *buffer, int size); |
34 | |
35 | inline bool GetMPEGAudioFrameSize(uint32_t header, int *frame_size, int *out_sampling_rate, |
36 | int *out_channels, int *out_bitrate, int *out_num_samples); |
37 | unsigned int Find_header(unsigned char *buffer, int *frame_size, int *out_sampling_rate, |
38 | int *out_channels, int *out_bitrate, int *out_num_samples); |
39 | bool refind_header(unsigned char *buffer, int *frame_size, unsigned char *header_buffer, |
40 | int offset, int *readbytes); |
41 | unsigned int Resync(uint32_t pos); |
42 | |
43 | fp_read_buffer fpread_buffer; |
44 | |
45 | int sample_rate; |
46 | int ChNum; |
47 | int frame_size; |
48 | int bitrate; |
49 | int num_samples; |
50 | |
51 | int *pStop_ReadBuf_Flag; |
52 | int64_t bytes_readed_sum_pre; |
53 | int64_t bytes_readed_sum; |
54 | |
55 | protected: |
56 | virtual ~MP3_MediaSource(); |
57 | |
58 | private: |
59 | bool mStarted; |
60 | sp<DataSource> mDataSource; |
61 | sp<MetaData> mMeta; |
62 | MediaBufferGroup *mGroup; |
63 | int64_t mCurrentTimeUs; |
64 | int Resynced_flag; |
65 | uint8_t *buf; |
66 | int Resync_framesize[3]; |
67 | int Resync_pos; |
68 | uint32_t mFixedHeader; |
69 | int start_flag; |
70 | int64_t SyncWordPosArray[5]; |
71 | int ResyncOccurFlag; |
72 | |
73 | MP3_MediaSource(const MP3_MediaSource &); |
74 | MP3_MediaSource &operator=(const MP3_MediaSource &); |
75 | }; |
76 | |
77 | |
78 | } |
79 | |
80 | #endif |
81 |