OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_ |
| 6 #define MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <list> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" |
| 15 #include "media/base/media_export.h" |
| 16 |
| 17 namespace media { |
| 18 class StreamParserBuffer; |
| 19 class VideoDecoderConfig; |
| 20 |
| 21 namespace mp2t { |
| 22 |
| 23 // Some constraints of the MSE spec are not necessarily met by video streams |
| 24 // inside an Mpeg2 TS stream. |
| 25 // The goal of the ES adapter is to modify the incoming buffers to meet these |
| 26 // constraints, e.g. |
| 27 // - get the frame duration, |
| 28 // - replace the leading non-key frames by the first key frame to avoid |
| 29 // creating a hole in the video timeline. |
| 30 class MEDIA_EXPORT EsAdapterVideo { |
| 31 public: |
| 32 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB; |
| 33 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; |
| 34 |
| 35 EsAdapterVideo( |
| 36 const NewVideoConfigCB& new_video_config_cb, |
| 37 const EmitBufferCB& emit_buffer_cb); |
| 38 ~EsAdapterVideo(); |
| 39 |
| 40 // Force the emission of the pending video buffers. |
| 41 void Flush(); |
| 42 |
| 43 // Reset the ES adapter to its initial state. |
| 44 void Reset(); |
| 45 |
| 46 // Provide the configuration that applies to the upcoming video buffers. |
| 47 void OnConfigChanged(const VideoDecoderConfig& video_decoder_config); |
| 48 |
| 49 // Provide a new video buffer. |
| 50 void OnNewBuffer( |
| 51 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer); |
| 52 |
| 53 private: |
| 54 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
| 55 typedef std::pair<int64, VideoDecoderConfig> ConfigEntry; |
| 56 |
| 57 void ProcessPendingBuffers(bool flush); |
| 58 |
| 59 // Return the PTS of the frame that comes just after |current_pts| in |
| 60 // presentation order. Return kNoTimestamp() if not found. |
| 61 base::TimeDelta GetNextFramePts(base::TimeDelta current_pts); |
| 62 |
| 63 // Replace the leading non key frames by |stream_parser_buffer| |
| 64 // (this one must be a key frame). |
| 65 void ReplaceDiscardedFrames( |
| 66 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer); |
| 67 |
| 68 NewVideoConfigCB new_video_config_cb_; |
| 69 EmitBufferCB emit_buffer_cb_; |
| 70 |
| 71 bool has_valid_config_; |
| 72 bool has_valid_frame_; |
| 73 |
| 74 // Duration of the last video frame. |
| 75 base::TimeDelta last_frame_duration_; |
| 76 |
| 77 // Association between a video config and a buffer index. |
| 78 std::list<ConfigEntry> config_list_; |
| 79 |
| 80 // Global index of the first buffer in |buffer_list_|. |
| 81 int64 buffer_index_; |
| 82 |
| 83 // List of buffer to be emitted and PTS of frames already emitted. |
| 84 BufferQueue buffer_list_; |
| 85 std::list<base::TimeDelta> emitted_pts_; |
| 86 |
| 87 // - Minimum PTS of discarded frames. |
| 88 // - DTS of discarded frames. |
| 89 base::TimeDelta discarded_frames_min_pts_; |
| 90 std::list<base::TimeDelta> discarded_frames_dts_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(EsAdapterVideo); |
| 93 }; |
| 94 |
| 95 } // namespace mp2t |
| 96 } // namespace media |
| 97 |
| 98 #endif // MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_ |
OLD | NEW |