Chromium Code Reviews| 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 namespace mp3 { | |
|
scherkus (not reviewing)
2013/09/03 19:34:22
FYI / personal pet-peeve but this is a bad example
acolwell GONE FROM CHROMIUM
2013/09/04 00:48:13
I'll remove the namespace. The WebM parser doesn't
| |
| 24 | |
| 25 class MEDIA_EXPORT MP3StreamParser : public StreamParser { | |
| 26 public: | |
| 27 MP3StreamParser(); | |
| 28 virtual ~MP3StreamParser(); | |
| 29 | |
| 30 virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, | |
|
scherkus (not reviewing)
2013/09/03 19:34:22
// StreamParser implementation.
acolwell GONE FROM CHROMIUM
2013/09/04 00:48:13
Done.
| |
| 31 const NewBuffersCB& new_buffers_cb, | |
| 32 const NewTextBuffersCB& text_cb, | |
| 33 const NeedKeyCB& need_key_cb, | |
| 34 const AddTextTrackCB& add_text_track_cb, | |
| 35 const NewMediaSegmentCB& new_segment_cb, | |
| 36 const base::Closure& end_of_segment_cb, | |
| 37 const LogCB& log_cb) OVERRIDE; | |
| 38 virtual void Flush() OVERRIDE; | |
| 39 virtual bool Parse(const uint8* buf, int size) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 enum State { | |
| 43 UNINITIALIZED, | |
| 44 INITIALIZED, | |
| 45 PARSE_ERROR | |
| 46 }; | |
| 47 | |
| 48 State state_; | |
| 49 | |
| 50 InitCB init_cb_; | |
| 51 NewConfigCB config_cb_; | |
| 52 NewBuffersCB new_buffers_cb_; | |
| 53 NewMediaSegmentCB new_segment_cb_; | |
| 54 base::Closure end_of_segment_cb_; | |
| 55 LogCB log_cb_; | |
| 56 | |
| 57 ByteQueue queue_; | |
| 58 | |
| 59 AudioDecoderConfig config_; | |
| 60 scoped_ptr<AudioTimestampHelper> timestamp_helper_; | |
| 61 bool in_media_segment_; | |
| 62 | |
| 63 void ChangeState(State state); | |
| 64 | |
| 65 // Parsing functions for various byte stream elements. | |
| 66 // |data| & |size| describe the data available for parsing. | |
| 67 // These functions are expected to consume an entire frame/header. | |
| 68 // It should only return a value greater than 0 when |data| has | |
| 69 // enough bytes to successfully parse & consume the entire element. | |
| 70 // Returns: | |
| 71 // > 0 : The number of bytes parsed. | |
| 72 // 0 : If more data is needed to parse the entire element. | |
| 73 // < 0 : An error was encountered during parsing. | |
| 74 int ParseFrameHeader(const uint8* data, int size, | |
| 75 int* frame_size, | |
| 76 int* sample_rate, | |
|
scherkus (not reviewing)
2013/09/03 19:34:22
document these last 3 args may be NULL
acolwell GONE FROM CHROMIUM
2013/09/04 00:48:13
Done.
| |
| 77 ChannelLayout* channel_layout, | |
| 78 int* sample_count) const; | |
| 79 int ParseMP3Frame(const uint8* data, int size); | |
| 80 int ParseIcecastHeader(const uint8* data, int size); | |
| 81 int ParseID3v1(const uint8* data, int size); | |
| 82 int ParseID3v2(const uint8* data, int size); | |
| 83 | |
| 84 // Parses an ID3v2 "sync safe" integer. | |
| 85 // |reader| - A BitReader to read from. | |
| 86 // |value| - Set to the integer value read, if true is returned. | |
| 87 // | |
| 88 // Returns true if the integer was successfully parsed and |value| | |
| 89 // was set. | |
| 90 // Returns false if an error was encountered. The state of |value| is | |
| 91 // undefined when false is returned. | |
| 92 bool ParseSyncSafeInt(BitReader* reader, int32* value); | |
| 93 | |
| 94 // Scans |data| for the next valid start code. | |
| 95 // Returns: | |
| 96 // > 0 : The number of bytes that should be skipped to reach the | |
| 97 // next start code.. | |
| 98 // 0 : If a valid start code was not found and more data is needed. | |
| 99 // < 0 : An error was encountered during parsing. | |
| 100 int FindNextValidStartCode(const uint8* data, int size) const; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(MP3StreamParser); | |
| 103 }; | |
| 104 | |
| 105 } // namespace mp3 | |
| 106 } // namespace media | |
| 107 | |
| 108 #endif // MEDIA_MP3_MP3_STREAM_PARSER_H_ | |
| OLD | NEW |