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

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

Issue 325503003: Fix seeking when the start time is non-zero. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FFmpeg only start time. Created 6 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
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 // Implements the Demuxer interface using FFmpeg's libavformat. At this time 5 // Implements the Demuxer interface using FFmpeg's libavformat. At this time
6 // will support demuxing any audio/video format thrown at it. The streams 6 // will support demuxing any audio/video format thrown at it. The streams
7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer 7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer
8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs 8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs
9 // can be used to create and initialize the corresponding FFmpeg decoder. 9 // can be used to create and initialize the corresponding FFmpeg decoder.
10 // 10 //
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Enters the end of stream state. After delivering remaining queued buffers 67 // Enters the end of stream state. After delivering remaining queued buffers
68 // only end of stream buffers will be delivered. 68 // only end of stream buffers will be delivered.
69 void SetEndOfStream(); 69 void SetEndOfStream();
70 70
71 // Drops queued buffers and clears end of stream state. 71 // Drops queued buffers and clears end of stream state.
72 void FlushBuffers(); 72 void FlushBuffers();
73 73
74 // Empties the queues and ignores any additional calls to Read(). 74 // Empties the queues and ignores any additional calls to Read().
75 void Stop(); 75 void Stop();
76 76
77 // Returns the duration of this stream. 77 base::TimeDelta duration() const { return duration_; }
78 base::TimeDelta duration();
79 78
80 // DemuxerStream implementation. 79 // DemuxerStream implementation.
81 virtual Type type() OVERRIDE; 80 virtual Type type() OVERRIDE;
82 virtual void Read(const ReadCB& read_cb) OVERRIDE; 81 virtual void Read(const ReadCB& read_cb) OVERRIDE;
83 virtual void EnableBitstreamConverter() OVERRIDE; 82 virtual void EnableBitstreamConverter() OVERRIDE;
84 virtual bool SupportsConfigChanges() OVERRIDE; 83 virtual bool SupportsConfigChanges() OVERRIDE;
85 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; 84 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE;
86 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; 85 virtual VideoDecoderConfig video_decoder_config() OVERRIDE;
87 86
88 // Returns the range of buffered data in this stream. 87 // Returns the range of buffered data in this stream.
89 Ranges<base::TimeDelta> GetBufferedRanges() const; 88 Ranges<base::TimeDelta> GetBufferedRanges() const;
90 89
91 // Returns elapsed time based on the already queued packets. 90 // Returns elapsed time based on the already queued packets.
92 // Used to determine stream duration when it's not known ahead of time. 91 // Used to determine stream duration when it's not known ahead of time.
93 base::TimeDelta GetElapsedTime() const; 92 base::TimeDelta GetElapsedTime() const;
94 93
95 // Returns true if this stream has capacity for additional data. 94 // Returns true if this stream has capacity for additional data.
96 bool HasAvailableCapacity(); 95 bool HasAvailableCapacity();
97 96
98 // Returns the total buffer size FFMpegDemuxerStream is holding onto. 97 // Returns the total buffer size FFMpegDemuxerStream is holding onto.
99 size_t MemoryUsage() const; 98 size_t MemoryUsage() const;
100 99
101 TextKind GetTextKind() const; 100 TextKind GetTextKind() const;
102 101
103 // Returns the value associated with |key| in the metadata for the avstream. 102 // Returns the value associated with |key| in the metadata for the avstream.
104 // Returns an empty string if the key is not present. 103 // Returns an empty string if the key is not present.
105 std::string GetMetadata(const char* key) const; 104 std::string GetMetadata(const char* key) const;
106 105
106 // Tells the DemuxerStream that all packets with negative timestamps should be
107 // marked for post-decode discard.
108 void enable_negative_timestamp_discard() {
109 discard_negative_timestamps_ = true;
110 }
111
107 private: 112 private:
108 friend class FFmpegDemuxerTest; 113 friend class FFmpegDemuxerTest;
109 114
110 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling 115 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling
111 // NotifyCapacityAvailable() if capacity is still available. 116 // NotifyCapacityAvailable() if capacity is still available.
112 void SatisfyPendingRead(); 117 void SatisfyPendingRead();
113 118
114 // Converts an FFmpeg stream timestamp into a base::TimeDelta. 119 // Converts an FFmpeg stream timestamp into a base::TimeDelta.
115 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, 120 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base,
116 int64 timestamp); 121 int64 timestamp);
(...skipping 12 matching lines...) Expand all
129 DecoderBufferQueue buffer_queue_; 134 DecoderBufferQueue buffer_queue_;
130 ReadCB read_cb_; 135 ReadCB read_cb_;
131 136
132 #if defined(USE_PROPRIETARY_CODECS) 137 #if defined(USE_PROPRIETARY_CODECS)
133 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; 138 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_;
134 #endif 139 #endif
135 140
136 bool bitstream_converter_enabled_; 141 bool bitstream_converter_enabled_;
137 142
138 std::string encryption_key_id_; 143 std::string encryption_key_id_;
144 bool discard_negative_timestamps_;
139 145
140 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); 146 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
141 }; 147 };
142 148
143 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { 149 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
144 public: 150 public:
145 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 151 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
146 DataSource* data_source, 152 DataSource* data_source,
147 const NeedKeyCB& need_key_cb, 153 const NeedKeyCB& need_key_cb,
148 const scoped_refptr<MediaLog>& media_log); 154 const scoped_refptr<MediaLog>& media_log);
149 virtual ~FFmpegDemuxer(); 155 virtual ~FFmpegDemuxer();
150 156
151 // Demuxer implementation. 157 // Demuxer implementation.
152 virtual void Initialize(DemuxerHost* host, 158 virtual void Initialize(DemuxerHost* host,
153 const PipelineStatusCB& status_cb, 159 const PipelineStatusCB& status_cb,
154 bool enable_text_tracks) OVERRIDE; 160 bool enable_text_tracks) OVERRIDE;
155 virtual void Stop(const base::Closure& callback) OVERRIDE; 161 virtual void Stop(const base::Closure& callback) OVERRIDE;
156 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; 162 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE;
157 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; 163 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE;
158 virtual base::TimeDelta GetStartTime() const OVERRIDE;
159 virtual base::Time GetTimelineOffset() const OVERRIDE; 164 virtual base::Time GetTimelineOffset() const OVERRIDE;
160 virtual Liveness GetLiveness() const OVERRIDE; 165 virtual Liveness GetLiveness() const OVERRIDE;
161 166
162 // Calls |need_key_cb_| with the initialization data encountered in the file. 167 // Calls |need_key_cb_| with the initialization data encountered in the file.
163 void FireNeedKey(const std::string& init_data_type, 168 void FireNeedKey(const std::string& init_data_type,
164 const std::string& encryption_key_id); 169 const std::string& encryption_key_id);
165 170
166 // Allow FFmpegDemuxerStream to notify us when there is updated information 171 // Allow FFmpegDemuxerStream to notify us when there is updated information
167 // about capacity and what buffered data is available. 172 // about capacity and what buffered data is available.
168 void NotifyCapacityAvailable(); 173 void NotifyCapacityAvailable();
169 void NotifyBufferingChanged(); 174 void NotifyBufferingChanged();
170 175
176 // The lowest demuxed timestamp. DemuxerStream's must use this to adjust
177 // packet timestamps such that external clients see a zero-based timeline.
178 base::TimeDelta start_time() const { return start_time_; }
179
171 private: 180 private:
172 // To allow tests access to privates. 181 // To allow tests access to privates.
173 friend class FFmpegDemuxerTest; 182 friend class FFmpegDemuxerTest;
174 183
175 // FFmpeg callbacks during initialization. 184 // FFmpeg callbacks during initialization.
176 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); 185 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result);
177 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); 186 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result);
178 187
179 // FFmpeg callbacks during seeking. 188 // FFmpeg callbacks during seeking.
180 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); 189 void OnSeekFrameDone(const PipelineStatusCB& cb, int result);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 247
239 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to 248 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to
240 // integrate with libavformat. 249 // integrate with libavformat.
241 DataSource* data_source_; 250 DataSource* data_source_;
242 251
243 scoped_refptr<MediaLog> media_log_; 252 scoped_refptr<MediaLog> media_log_;
244 253
245 // Derived bitrate after initialization has completed. 254 // Derived bitrate after initialization has completed.
246 int bitrate_; 255 int bitrate_;
247 256
248 // The first timestamp of the opened media file. This is used to set the 257 // The first timestamp of the audio or video stream, whichever is lower. This
249 // starting clock value to match the timestamps in the media file. Default 258 // is used to adjust timestamps so that external consumers always see a zero
250 // is 0. 259 // based timeline.
251 base::TimeDelta start_time_; 260 base::TimeDelta start_time_;
252 261
253 // The Time associated with timestamp 0. Set to a null 262 // The Time associated with timestamp 0. Set to a null
254 // time if the file doesn't have an association to Time. 263 // time if the file doesn't have an association to Time.
255 base::Time timeline_offset_; 264 base::Time timeline_offset_;
256 265
257 // Liveness of the stream. 266 // Liveness of the stream.
258 Liveness liveness_; 267 Liveness liveness_;
259 268
260 // Whether text streams have been enabled for this demuxer. 269 // Whether text streams have been enabled for this demuxer.
261 bool text_enabled_; 270 bool text_enabled_;
262 271
263 // Set if we know duration of the audio stream. Used when processing end of 272 // Set if we know duration of the audio stream. Used when processing end of
264 // stream -- at this moment we definitely know duration. 273 // stream -- at this moment we definitely know duration.
265 bool duration_known_; 274 bool duration_known_;
266 275
267 // FFmpegURLProtocol implementation and corresponding glue bits. 276 // FFmpegURLProtocol implementation and corresponding glue bits.
268 scoped_ptr<BlockingUrlProtocol> url_protocol_; 277 scoped_ptr<BlockingUrlProtocol> url_protocol_;
269 scoped_ptr<FFmpegGlue> glue_; 278 scoped_ptr<FFmpegGlue> glue_;
270 279
271 const NeedKeyCB need_key_cb_; 280 const NeedKeyCB need_key_cb_;
272 281
282 // The index of the stream in |streams_| to use for seeking. Chosen by the
283 // stream with the lowest starting timestamp.
284 int stream_index_for_seeking_;
285
273 // NOTE: Weak pointers must be invalidated before all other member variables. 286 // NOTE: Weak pointers must be invalidated before all other member variables.
274 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; 287 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_;
275 288
276 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 289 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
277 }; 290 };
278 291
279 } // namespace media 292 } // namespace media
280 293
281 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 294 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698