Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1680)

Unified Diff: media/mp3/mp3_stream_parser.h

Issue 23454006: Implement experimental MP3 support for Media Source API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/mp3/mp3_stream_parser.h
diff --git a/media/mp3/mp3_stream_parser.h b/media/mp3/mp3_stream_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..95a4f046d623d98eb422a1394add4283661e2a7f
--- /dev/null
+++ b/media/mp3/mp3_stream_parser.h
@@ -0,0 +1,108 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_MP3_MP3_STREAM_PARSER_H_
+#define MEDIA_MP3_MP3_STREAM_PARSER_H_
+
+#include <set>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "media/base/audio_decoder_config.h"
+#include "media/base/audio_timestamp_helper.h"
+#include "media/base/byte_queue.h"
+#include "media/base/media_export.h"
+#include "media/base/stream_parser.h"
+
+namespace media {
+
+class BitReader;
+
+namespace mp3 {
+
+class MEDIA_EXPORT MP3StreamParser : public StreamParser {
+ public:
+ MP3StreamParser();
+ virtual ~MP3StreamParser();
+
+ virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb,
+ const NewBuffersCB& new_buffers_cb,
+ const NewTextBuffersCB& text_cb,
+ const NeedKeyCB& need_key_cb,
+ const AddTextTrackCB& add_text_track_cb,
+ const NewMediaSegmentCB& new_segment_cb,
+ const base::Closure& end_of_segment_cb,
+ const LogCB& log_cb) OVERRIDE;
+ virtual void Flush() OVERRIDE;
+ virtual bool Parse(const uint8* buf, int size) OVERRIDE;
+
+ private:
+ enum State {
+ UNINITIALIZED,
+ INITIALIZED,
+ ERROR
+ };
+
+ State state_;
+
+ InitCB init_cb_;
+ NewConfigCB config_cb_;
+ NewBuffersCB new_buffers_cb_;
+ NewMediaSegmentCB new_segment_cb_;
+ base::Closure end_of_segment_cb_;
+ LogCB log_cb_;
+
+ ByteQueue queue_;
+
+ AudioDecoderConfig config_;
+ scoped_ptr<AudioTimestampHelper> timestamp_helper_;
+ bool in_media_segment_;
+
+ void ChangeState(State state);
+
+ // Parsing functions for various byte stream elements.
+ // |data| & |size| describe the data available for parsing.
+ // These functions are expected to consume an entire frame/header.
+ // It should only return a value greater than 0 when |data| has
+ // enough bytes to successfully parse & consume the entire element.
+ // Returns:
+ // > 0 : The number of bytes parsed.
+ // 0 : If more data is needed to parse the entire element.
+ // < 0 : An error was encountered during parsing.
+ int ParseFrameHeader(const uint8* data, int size,
+ int* frame_size,
+ int* sample_rate,
+ ChannelLayout* channel_layout,
+ int* sample_count) const;
+ int ParseMP3Frame(const uint8* data, int size);
+ int ParseIcecastHeader(const uint8* data, int size);
+ int ParseID3v1(const uint8* data, int size);
+ int ParseID3v2(const uint8* data, int size);
+
+ // Parses an ID3v2 "sync safe" integer.
+ // |reader| - A BitReader to read from.
+ // |value| - Set to the integer value read, if true is returned.
+ //
+ // Returns true if the integer was successfully parsed and |value|
+ // was set.
+ // Returns false if an error was encountered. The state of |value| is
+ // undefined when false is returned.
+ bool ParseSyncSafeInt(BitReader* reader, int32* value);
+
+ // Scans |data| for the next valid start code.
+ // Returns:
+ // > 0 : The number of bytes that should be skipped to reach the
+ // next start code..
+ // 0 : If a valid start code was not found and more data is needed.
+ // < 0 : An error was encountered during parsing.
+ int FindNextValidStartCode(const uint8* data, int size) const;
+
+ DISALLOW_COPY_AND_ASSIGN(MP3StreamParser);
+};
+
+} // namespace mp3
+} // namespace media
+
+#endif // MEDIA_MP3_MP3_STREAM_PARSER_H_

Powered by Google App Engine
This is Rietveld 408576698