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