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

Side by Side Diff: media/filters/chunk_demuxer.h

Issue 10558011: Fix ChunkDemuxer so it properly outputs buffered ranges. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more CR comments and added an end of stream test case. Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/ranges_unittest.cc ('k') | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ 5 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_
6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ 6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "media/base/byte_queue.h" 14 #include "media/base/byte_queue.h"
15 #include "media/base/demuxer.h" 15 #include "media/base/demuxer.h"
16 #include "media/base/ranges.h"
16 #include "media/base/stream_parser.h" 17 #include "media/base/stream_parser.h"
17 #include "media/filters/source_buffer_stream.h" 18 #include "media/filters/source_buffer_stream.h"
18 19
19 namespace media { 20 namespace media {
20 21
21 class ChunkDemuxerClient; 22 class ChunkDemuxerClient;
22 class ChunkDemuxerStream; 23 class ChunkDemuxerStream;
23 class FFmpegURLProtocol; 24 class FFmpegURLProtocol;
24 25
25 // Demuxer implementation that allows chunks of media data to be passed 26 // Demuxer implementation that allows chunks of media data to be passed
26 // from JavaScript to the media stack. 27 // from JavaScript to the media stack.
27 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { 28 class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
28 public: 29 public:
29 enum Status { 30 enum Status {
30 kOk, // ID added w/o error. 31 kOk, // ID added w/o error.
31 kNotSupported, // Type specified is not supported. 32 kNotSupported, // Type specified is not supported.
32 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. 33 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs.
33 }; 34 };
34 35
35 typedef std::vector<std::pair<base::TimeDelta, base::TimeDelta> > Ranges;
36
37 explicit ChunkDemuxer(ChunkDemuxerClient* client); 36 explicit ChunkDemuxer(ChunkDemuxerClient* client);
38 37
39 // Demuxer implementation. 38 // Demuxer implementation.
40 virtual void Initialize(DemuxerHost* host, 39 virtual void Initialize(DemuxerHost* host,
41 const PipelineStatusCB& cb) OVERRIDE; 40 const PipelineStatusCB& cb) OVERRIDE;
42 virtual void Stop(const base::Closure& callback) OVERRIDE; 41 virtual void Stop(const base::Closure& callback) OVERRIDE;
43 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; 42 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE;
44 virtual void OnAudioRendererDisabled() OVERRIDE; 43 virtual void OnAudioRendererDisabled() OVERRIDE;
45 virtual scoped_refptr<DemuxerStream> GetStream( 44 virtual scoped_refptr<DemuxerStream> GetStream(
46 DemuxerStream::Type type) OVERRIDE; 45 DemuxerStream::Type type) OVERRIDE;
(...skipping 11 matching lines...) Expand all
58 // kReachedIdLimit is returned if the demuxer cannot handle another ID right 57 // kReachedIdLimit is returned if the demuxer cannot handle another ID right
59 // now. 58 // now.
60 Status AddId(const std::string& id, const std::string& type, 59 Status AddId(const std::string& id, const std::string& type,
61 std::vector<std::string>& codecs); 60 std::vector<std::string>& codecs);
62 61
63 // Removed an ID & associated resources that were previously added with 62 // Removed an ID & associated resources that were previously added with
64 // AddId(). 63 // AddId().
65 void RemoveId(const std::string& id); 64 void RemoveId(const std::string& id);
66 65
67 // Gets the currently buffered ranges for the specified ID. 66 // Gets the currently buffered ranges for the specified ID.
68 // Returns true if data is buffered & |ranges_out| is set to the 67 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const;
69 // time ranges currently buffered.
70 // Returns false if no data is buffered.
71 bool GetBufferedRanges(const std::string& id, Ranges* ranges_out) const;
72 68
73 // Appends media data to the source buffer associated with |id|. Returns 69 // Appends media data to the source buffer associated with |id|. Returns
74 // false if this method is called in an invalid state. 70 // false if this method is called in an invalid state.
75 bool AppendData(const std::string& id, const uint8* data, size_t length); 71 bool AppendData(const std::string& id, const uint8* data, size_t length);
76 72
77 // Aborts parsing the current segment and reset the parser to a state where 73 // Aborts parsing the current segment and reset the parser to a state where
78 // it can accept a new segment. 74 // it can accept a new segment.
79 void Abort(const std::string& id); 75 void Abort(const std::string& id);
80 76
81 // Signals an EndOfStream request. 77 // Signals an EndOfStream request.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void OnStreamParserInitDone(bool success, base::TimeDelta duration); 110 void OnStreamParserInitDone(bool success, base::TimeDelta duration);
115 bool OnNewConfigs(bool has_audio, bool has_video, 111 bool OnNewConfigs(bool has_audio, bool has_video,
116 const AudioDecoderConfig& audio_config, 112 const AudioDecoderConfig& audio_config,
117 const VideoDecoderConfig& video_config); 113 const VideoDecoderConfig& video_config);
118 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers); 114 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers);
119 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers); 115 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers);
120 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size); 116 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size);
121 void OnNewMediaSegment(const std::string& source_id, 117 void OnNewMediaSegment(const std::string& source_id,
122 base::TimeDelta start_timestamp); 118 base::TimeDelta start_timestamp);
123 119
124 // Helper functions for calculating GetBufferedRanges(). 120 // Computes the intersection between the video & audio
125 bool CopyIntoRanges( 121 // buffered ranges.
126 const SourceBufferStream::TimespanList& timespans, 122 Ranges<base::TimeDelta> ComputeIntersection() const;
127 Ranges* ranges_out) const;
128 void AddIntersectionRange(
129 SourceBufferStream::Timespan timespan_a,
130 SourceBufferStream::Timespan timespan_b,
131 bool last_range_after_ended,
132 Ranges* ranges_out) const;
133 123
134 mutable base::Lock lock_; 124 mutable base::Lock lock_;
135 State state_; 125 State state_;
136 126
137 DemuxerHost* host_; 127 DemuxerHost* host_;
138 ChunkDemuxerClient* client_; 128 ChunkDemuxerClient* client_;
139 PipelineStatusCB init_cb_; 129 PipelineStatusCB init_cb_;
140 PipelineStatusCB seek_cb_; 130 PipelineStatusCB seek_cb_;
141 131
142 scoped_refptr<ChunkDemuxerStream> audio_; 132 scoped_refptr<ChunkDemuxerStream> audio_;
143 scoped_refptr<ChunkDemuxerStream> video_; 133 scoped_refptr<ChunkDemuxerStream> video_;
144 134
145 int64 buffered_bytes_;
146
147 base::TimeDelta duration_; 135 base::TimeDelta duration_;
148 136
149 typedef std::map<std::string, StreamParser*> StreamParserMap; 137 typedef std::map<std::string, StreamParser*> StreamParserMap;
150 StreamParserMap stream_parser_map_; 138 StreamParserMap stream_parser_map_;
151 139
152 // Used to ensure that (1) config data matches the type and codec provided in 140 // Used to ensure that (1) config data matches the type and codec provided in
153 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be 141 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be
154 // removed with RemoveID() but can not be re-added (yet). 142 // removed with RemoveID() but can not be re-added (yet).
155 std::string source_id_audio_; 143 std::string source_id_audio_;
156 std::string source_id_video_; 144 std::string source_id_video_;
157 145
158 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); 146 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer);
159 }; 147 };
160 148
161 } // namespace media 149 } // namespace media
162 150
163 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ 151 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/base/ranges_unittest.cc ('k') | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698