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

Unified Diff: media/filters/chunk_demuxer.h

Issue 7203002: Adding ChunkDemuxer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests and bug fixes Created 9 years, 6 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/filters/chunk_demuxer.h
diff --git a/media/filters/chunk_demuxer.h b/media/filters/chunk_demuxer.h
new file mode 100644
index 0000000000000000000000000000000000000000..7f599e6017f58dc0bb5b23c975437e1801db03e0
--- /dev/null
+++ b/media/filters/chunk_demuxer.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2011 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_FILTERS_CHUNK_DEMUXER_H_
+#define MEDIA_FILTERS_CHUNK_DEMUXER_H_
+
+#include <list>
+
+#include "base/synchronization/lock.h"
+#include "media/base/filters.h"
+#include "media/webm/webm_cluster_parser.h"
+
+struct AVFormatContext;
+
+namespace media {
+
+class ChunkDemuxerStream;
+
+// Demuxer implementation that allows chunks of WebM media data to be passed
+// from JavaScript to the media stack.
+class ChunkDemuxer : public Demuxer {
+ public:
+ ChunkDemuxer();
+ virtual ~ChunkDemuxer();
+
+ bool Init(const uint8* data, int size);
+
+ // Filter implementation.
+ virtual void set_host(FilterHost* filter_host);
+ virtual void Stop(FilterCallback* callback);
+ virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb);
+ virtual void OnAudioRendererDisabled();
+ virtual void SetPreload(Preload preload);
+
+ // Demuxer implementation.
+ virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type);
+ virtual base::TimeDelta GetStartTime() const;
+
+ // Methods used by MediaDataSink
+ void FlushData();
+ bool AddData(const uint8* data, unsigned length);
+ void Shutdown();
+
+ private:
+ enum State {
+ WAITING_FOR_INIT,
+ INITIALIZED,
+ INIT_ERROR,
+ SHUTDOWN,
+ };
+
+ void ChangeState(State new_state);
+
+ // Generates an AVFormatContext for the INFO & TRACKS elements contained
+ // in |data|. Returns NULL if parsing |data| fails.
+ AVFormatContext* CreateFormatContext(const uint8* data, int size) const;
+
+ // Sets up |audio_| & |video_| DemuxerStreams based on the data in
+ // |format_context_|. Returns false if no valid audio or video stream were
+ // found.
+ bool SetupStreams();
+
+ // Parse all the buffers in |pending_buffers_|. Returns false if parsing one
+ // of the buffers fails.
+ bool ParsePendingBuffers();
+
+ // Parse a buffer that was passed to AddData(). |data| is expected to contain
+ // one or more WebM Clusters. Returns false if parsing the data fails.
+ bool ParseAndAddData_Locked(const uint8* data, int length);
+
+ base::Lock lock_;
+ State state_;
+
+ FilterStatusCB seek_cb_;
+
+ scoped_refptr<ChunkDemuxerStream> audio_;
+ scoped_refptr<ChunkDemuxerStream> video_;
+
+ AVFormatContext* format_context_;
+
+ int64 buffered_bytes_;
+
+ base::TimeDelta duration_;
+
+ scoped_ptr<WebMClusterParser> cluster_parser_;
+
+ typedef std::list<scoped_refptr<media::Buffer> > BufferList;
+ BufferList pending_buffers_;
+
+ // Should a Seek() call wait for more data before calling the
+ // callback.
+ bool seek_waits_for_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer);
+};
+
+} // namespace media
+
+#endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_

Powered by Google App Engine
This is Rietveld 408576698