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..3752f75a81193c56f7e7f49ea72769c2722d9c50 |
--- /dev/null |
+++ b/media/filters/chunk_demuxer.h |
@@ -0,0 +1,98 @@ |
+// 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_; |
+ |
+ base::TimeDelta seek_time_; |
+ FilterStatusCB seek_cb_; |
+ |
+ scoped_refptr<ChunkDemuxerStream> audio_; |
+ scoped_refptr<ChunkDemuxerStream> video_; |
+ |
+ AVFormatContext* format_context_; |
+ |
+ int64 buffered_bytes_; |
+ |
+ bool first_seek_; |
+ base::TimeDelta duration_; |
+ |
+ scoped_ptr<WebMClusterParser> cluster_parser_; |
+ |
+ typedef std::list<scoped_refptr<media::Buffer> > BufferList; |
+ BufferList pending_buffers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |