OLD | NEW |
---|---|
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/ranges.h" |
17 #include "media/base/stream_parser.h" | 17 #include "media/base/stream_parser.h" |
18 #include "media/filters/source_buffer_stream.h" | 18 #include "media/filters/source_buffer_stream.h" |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 | 21 |
22 class ChunkDemuxerClient; | 22 class ChunkDemuxerClient; |
23 class ChunkDemuxerStream; | 23 class ChunkDemuxerStream; |
24 class FFmpegURLProtocol; | 24 class FFmpegURLProtocol; |
25 class SourceInfo; | |
25 | 26 |
26 // Demuxer implementation that allows chunks of media data to be passed | 27 // Demuxer implementation that allows chunks of media data to be passed |
27 // from JavaScript to the media stack. | 28 // from JavaScript to the media stack. |
28 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { | 29 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { |
29 public: | 30 public: |
30 enum Status { | 31 enum Status { |
31 kOk, // ID added w/o error. | 32 kOk, // ID added w/o error. |
32 kNotSupported, // Type specified is not supported. | 33 kNotSupported, // Type specified is not supported. |
33 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. | 34 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. |
34 }; | 35 }; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; | 68 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; |
68 | 69 |
69 // Appends media data to the source buffer associated with |id|. Returns | 70 // Appends media data to the source buffer associated with |id|. Returns |
70 // false if this method is called in an invalid state. | 71 // false if this method is called in an invalid state. |
71 bool AppendData(const std::string& id, const uint8* data, size_t length); | 72 bool AppendData(const std::string& id, const uint8* data, size_t length); |
72 | 73 |
73 // Aborts parsing the current segment and reset the parser to a state where | 74 // Aborts parsing the current segment and reset the parser to a state where |
74 // it can accept a new segment. | 75 // it can accept a new segment. |
75 void Abort(const std::string& id); | 76 void Abort(const std::string& id); |
76 | 77 |
78 // Sets a time |offset| in seconds to be applied to subsequent buffers | |
79 // appended to the source buffer assicated with |id|. | |
80 bool TimestampOffset(const std::string& id, float offset); | |
acolwell GONE FROM CHROMIUM
2012/07/20 18:21:01
nit: SetTimestampOffset()?
vrk (LEFT CHROMIUM)
2012/07/25 17:16:48
Done, and changed other similar methods.
| |
81 | |
77 // Signals an EndOfStream request. | 82 // Signals an EndOfStream request. |
78 // Returns false if called in an unexpected state or if there is a gap between | 83 // Returns false if called in an unexpected state or if there is a gap between |
79 // the current position and the end of the buffered data. | 84 // the current position and the end of the buffered data. |
80 bool EndOfStream(PipelineStatus status); | 85 bool EndOfStream(PipelineStatus status); |
81 void Shutdown(); | 86 void Shutdown(); |
82 | 87 |
83 protected: | 88 protected: |
84 virtual ~ChunkDemuxer(); | 89 virtual ~ChunkDemuxer(); |
85 | 90 |
86 private: | 91 private: |
(...skipping 23 matching lines...) Expand all Loading... | |
110 // StreamParser callbacks. | 115 // StreamParser callbacks. |
111 void OnStreamParserInitDone(bool success, base::TimeDelta duration); | 116 void OnStreamParserInitDone(bool success, base::TimeDelta duration); |
112 bool OnNewConfigs(bool has_audio, bool has_video, | 117 bool OnNewConfigs(bool has_audio, bool has_video, |
113 const AudioDecoderConfig& audio_config, | 118 const AudioDecoderConfig& audio_config, |
114 const VideoDecoderConfig& video_config); | 119 const VideoDecoderConfig& video_config); |
115 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers); | 120 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers); |
116 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers); | 121 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers); |
117 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size); | 122 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size); |
118 void OnNewMediaSegment(const std::string& source_id, | 123 void OnNewMediaSegment(const std::string& source_id, |
119 base::TimeDelta start_timestamp); | 124 base::TimeDelta start_timestamp); |
125 void OnEndOfMediaSegment(const std::string& source_id); | |
120 | 126 |
121 // Computes the intersection between the video & audio | 127 // Computes the intersection between the video & audio |
122 // buffered ranges. | 128 // buffered ranges. |
123 Ranges<base::TimeDelta> ComputeIntersection() const; | 129 Ranges<base::TimeDelta> ComputeIntersection() const; |
124 | 130 |
131 // Applies |time_offset| to the timestamps of |buffers|. | |
132 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers, | |
133 base::TimeDelta timestamp_offset); | |
134 | |
125 mutable base::Lock lock_; | 135 mutable base::Lock lock_; |
126 State state_; | 136 State state_; |
127 | 137 |
128 DemuxerHost* host_; | 138 DemuxerHost* host_; |
129 ChunkDemuxerClient* client_; | 139 ChunkDemuxerClient* client_; |
130 PipelineStatusCB init_cb_; | 140 PipelineStatusCB init_cb_; |
131 PipelineStatusCB seek_cb_; | 141 PipelineStatusCB seek_cb_; |
132 | 142 |
133 scoped_refptr<ChunkDemuxerStream> audio_; | 143 scoped_refptr<ChunkDemuxerStream> audio_; |
134 scoped_refptr<ChunkDemuxerStream> video_; | 144 scoped_refptr<ChunkDemuxerStream> video_; |
135 | 145 |
136 base::TimeDelta duration_; | 146 base::TimeDelta duration_; |
137 | 147 |
138 typedef std::map<std::string, StreamParser*> StreamParserMap; | 148 typedef std::map<std::string, StreamParser*> StreamParserMap; |
139 StreamParserMap stream_parser_map_; | 149 StreamParserMap stream_parser_map_; |
140 | 150 |
151 // Contains state belonging to a media source. | |
152 struct StreamInfo { | |
acolwell GONE FROM CHROMIUM
2012/07/20 18:21:01
nit: s/StreamInfo/SourceInfo or SourceIdInfo since
vrk (LEFT CHROMIUM)
2012/07/25 17:16:48
Done.
| |
153 base::TimeDelta timestamp_offset; | |
154 bool can_update_offset; | |
155 }; | |
156 typedef std::map<std::string, StreamInfo> StreamInfoMap; | |
157 StreamInfoMap stream_info_map_; | |
158 | |
141 // Used to ensure that (1) config data matches the type and codec provided in | 159 // Used to ensure that (1) config data matches the type and codec provided in |
142 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be | 160 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be |
143 // removed with RemoveID() but can not be re-added (yet). | 161 // removed with RemoveID() but can not be re-added (yet). |
144 std::string source_id_audio_; | 162 std::string source_id_audio_; |
145 std::string source_id_video_; | 163 std::string source_id_video_; |
146 | 164 |
147 base::TimeDelta start_time_; | 165 base::TimeDelta start_time_; |
148 | 166 |
149 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 167 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
150 }; | 168 }; |
151 | 169 |
152 } // namespace media | 170 } // namespace media |
153 | 171 |
154 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 172 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |