| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 6 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 7 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 7 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 8 | 8 |
| 9 #include <queue> |
| 10 |
| 9 #include "media/base/factory.h" | 11 #include "media/base/factory.h" |
| 10 #include "media/filters/decoder_base.h" | 12 #include "media/filters/decoder_base.h" |
| 11 | 13 |
| 14 // FFmpeg types. |
| 15 struct AVCodecContext; |
| 16 struct AVFrame; |
| 17 |
| 12 namespace media { | 18 namespace media { |
| 13 | 19 |
| 14 //------------------------------------------------------------------------------ | 20 //------------------------------------------------------------------------------ |
| 15 | 21 |
| 16 class FFmpegVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { | 22 class FFmpegVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { |
| 17 public: | 23 public: |
| 18 static FilterFactory* CreateFactory() { | 24 static FilterFactory* CreateFactory() { |
| 19 return new FilterFactoryImpl0<FFmpegVideoDecoder>(); | 25 return new FilterFactoryImpl0<FFmpegVideoDecoder>(); |
| 20 } | 26 } |
| 21 | 27 |
| 22 static bool IsMediaFormatSupported(const MediaFormat& media_format); | 28 static bool IsMediaFormatSupported(const MediaFormat& media_format); |
| 23 | 29 |
| 24 virtual bool OnInitialize(DemuxerStream* demuxer_stream); | 30 virtual bool OnInitialize(DemuxerStream* demuxer_stream); |
| 25 | 31 |
| 26 virtual void OnDecode(Buffer* input); | 32 virtual void OnDecode(Buffer* buffer); |
| 27 | 33 |
| 28 private: | 34 private: |
| 29 friend class FilterFactoryImpl0<FFmpegVideoDecoder>; | 35 friend class FilterFactoryImpl0<FFmpegVideoDecoder>; |
| 30 FFmpegVideoDecoder(); | 36 FFmpegVideoDecoder(); |
| 31 virtual ~FFmpegVideoDecoder(); | 37 virtual ~FFmpegVideoDecoder(); |
| 32 | 38 |
| 39 bool EnqueueVideoFrame(VideoSurface::Format surface_format, |
| 40 const AVFrame& frame); |
| 41 |
| 42 void CopyPlane(size_t plane, const VideoSurface& surface, |
| 43 const AVFrame& frame); |
| 44 |
| 45 size_t width_; |
| 46 size_t height_; |
| 47 |
| 48 // FFmpeg outputs packets in decode timestamp (dts) order, which may not |
| 49 // always be in presentation timestamp (pts) order. Therefore, when Process |
| 50 // is called we cannot assume that the pts of the input |buffer| passed to the |
| 51 // OnDecode() method is necessarily the pts of video frame. For example: |
| 52 // |
| 53 // Process() Timestamp Timestamp |
| 54 // Call # Buffer In Buffer Out |
| 55 // 1 1 1 |
| 56 // 2 3 --- <--- frame 3 buffered by FFmpeg |
| 57 // 3 2 2 |
| 58 // 4 4 3 <--- copying timestamp 4 and 6 would be |
| 59 // 5 6 4 <-' incorrect, which is why we sort and |
| 60 // 6 5 5 queue incoming timestamps |
| 61 |
| 62 // A queue entry that holds a timestamp and a duration. |
| 63 struct TimeTuple { |
| 64 base::TimeDelta timestamp; |
| 65 base::TimeDelta duration; |
| 66 |
| 67 bool operator<(const TimeTuple& other) const { |
| 68 return timestamp >= other.timestamp; |
| 69 } |
| 70 }; |
| 71 |
| 72 // A priority queue of presentation TimeTuples. |
| 73 typedef std::priority_queue<TimeTuple> TimeQueue; |
| 74 TimeQueue time_queue_; |
| 75 |
| 76 AVCodecContext* codec_context_; |
| 77 |
| 33 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); | 78 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); |
| 34 }; | 79 }; |
| 35 | 80 |
| 36 } // namespace media | 81 } // namespace media |
| 37 | 82 |
| 38 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 83 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| OLD | NEW |