OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_MP3_MP3_STREAM_PARSER_H_ |
| 6 #define MEDIA_MP3_MP3_STREAM_PARSER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/audio_timestamp_helper.h" |
| 15 #include "media/base/byte_queue.h" |
| 16 #include "media/base/media_export.h" |
| 17 #include "media/base/stream_parser.h" |
| 18 |
| 19 namespace media { |
| 20 |
| 21 class BitReader; |
| 22 |
| 23 class MEDIA_EXPORT MP3StreamParser : public StreamParser { |
| 24 public: |
| 25 MP3StreamParser(); |
| 26 virtual ~MP3StreamParser(); |
| 27 |
| 28 // StreamParser implementation. |
| 29 virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, |
| 30 const NewBuffersCB& new_buffers_cb, |
| 31 const NewTextBuffersCB& text_cb, |
| 32 const NeedKeyCB& need_key_cb, |
| 33 const AddTextTrackCB& add_text_track_cb, |
| 34 const NewMediaSegmentCB& new_segment_cb, |
| 35 const base::Closure& end_of_segment_cb, |
| 36 const LogCB& log_cb) OVERRIDE; |
| 37 virtual void Flush() OVERRIDE; |
| 38 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 39 |
| 40 private: |
| 41 enum State { |
| 42 UNINITIALIZED, |
| 43 INITIALIZED, |
| 44 PARSE_ERROR |
| 45 }; |
| 46 |
| 47 State state_; |
| 48 |
| 49 InitCB init_cb_; |
| 50 NewConfigCB config_cb_; |
| 51 NewBuffersCB new_buffers_cb_; |
| 52 NewMediaSegmentCB new_segment_cb_; |
| 53 base::Closure end_of_segment_cb_; |
| 54 LogCB log_cb_; |
| 55 |
| 56 ByteQueue queue_; |
| 57 |
| 58 AudioDecoderConfig config_; |
| 59 scoped_ptr<AudioTimestampHelper> timestamp_helper_; |
| 60 bool in_media_segment_; |
| 61 |
| 62 void ChangeState(State state); |
| 63 |
| 64 // Parsing functions for various byte stream elements. |
| 65 // |data| & |size| describe the data available for parsing. |
| 66 // These functions are expected to consume an entire frame/header. |
| 67 // It should only return a value greater than 0 when |data| has |
| 68 // enough bytes to successfully parse & consume the entire element. |
| 69 // |
| 70 // |frame_size| - Required parameter that is set to the size of the frame, in |
| 71 // bytes, including the frame header if the function returns a value > 0. |
| 72 // |sample_rate| - Optional parameter that is set to the sample rate |
| 73 // of the frame if this function returns a value > 0. |
| 74 // |channel_layout| - Optional parameter that is set to the channel_layout |
| 75 // of the frame if this function returns a value > 0. |
| 76 // |sample_count| - Optional parameter that is set to the number of samples |
| 77 // in the frame if this function returns a value > 0. |
| 78 // |
| 79 // |sample_rate|, |channel_layout|, |sample_count| may be NULL if the caller |
| 80 // is not interested in receiving these values from the frame header. |
| 81 // |
| 82 // Returns: |
| 83 // > 0 : The number of bytes parsed. |
| 84 // 0 : If more data is needed to parse the entire element. |
| 85 // < 0 : An error was encountered during parsing. |
| 86 int ParseFrameHeader(const uint8* data, int size, |
| 87 int* frame_size, |
| 88 int* sample_rate, |
| 89 ChannelLayout* channel_layout, |
| 90 int* sample_count) const; |
| 91 int ParseMP3Frame(const uint8* data, int size); |
| 92 int ParseIcecastHeader(const uint8* data, int size); |
| 93 int ParseID3v1(const uint8* data, int size); |
| 94 int ParseID3v2(const uint8* data, int size); |
| 95 |
| 96 // Parses an ID3v2 "sync safe" integer. |
| 97 // |reader| - A BitReader to read from. |
| 98 // |value| - Set to the integer value read, if true is returned. |
| 99 // |
| 100 // Returns true if the integer was successfully parsed and |value| |
| 101 // was set. |
| 102 // Returns false if an error was encountered. The state of |value| is |
| 103 // undefined when false is returned. |
| 104 bool ParseSyncSafeInt(BitReader* reader, int32* value); |
| 105 |
| 106 // Scans |data| for the next valid start code. |
| 107 // Returns: |
| 108 // > 0 : The number of bytes that should be skipped to reach the |
| 109 // next start code.. |
| 110 // 0 : If a valid start code was not found and more data is needed. |
| 111 // < 0 : An error was encountered during parsing. |
| 112 int FindNextValidStartCode(const uint8* data, int size) const; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(MP3StreamParser); |
| 115 }; |
| 116 |
| 117 } // namespace media |
| 118 |
| 119 #endif // MEDIA_MP3_MP3_STREAM_PARSER_H_ |
OLD | NEW |