// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_ #define MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_ #include #include #include #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "media/base/media_export.h" namespace media { class StreamParserBuffer; class VideoDecoderConfig; namespace mp2t { // Some constraints of the MSE spec are not necessarily met by video streams // inside an Mpeg2 TS stream. // The goal of the ES adapter is to modify the incoming buffers to meet these // constraints, e.g. // - get the frame duration, // - replace the leading non-key frames by the first key frame to avoid // creating a hole in the video timeline. class MEDIA_EXPORT EsAdapterVideo { public: typedef base::Callback NewVideoConfigCB; typedef base::Callback)> EmitBufferCB; EsAdapterVideo( const NewVideoConfigCB& new_video_config_cb, const EmitBufferCB& emit_buffer_cb); ~EsAdapterVideo(); // Force the emission of the pending video buffers. void Flush(); // Reset the ES adapter to its initial state. void Reset(); // Provide the configuration that applies to the upcoming video buffers. void OnConfigChanged(const VideoDecoderConfig& video_decoder_config); // Provide a new video buffer. void OnNewBuffer( const scoped_refptr& stream_parser_buffer); private: typedef std::deque > BufferQueue; typedef std::pair ConfigEntry; void ProcessPendingBuffers(bool flush); // Return the PTS of the frame that comes just after |current_pts| in // presentation order. Return kNoTimestamp() if not found. base::TimeDelta GetNextFramePts(base::TimeDelta current_pts); // Replace the leading non key frames by |stream_parser_buffer| // (this one must be a key frame). void ReplaceDiscardedFrames( const scoped_refptr& stream_parser_buffer); NewVideoConfigCB new_video_config_cb_; EmitBufferCB emit_buffer_cb_; bool has_valid_config_; bool has_valid_frame_; // Duration of the last video frame. base::TimeDelta last_frame_duration_; // Association between a video config and a buffer index. std::list config_list_; // Global index of the first buffer in |buffer_list_|. int64 buffer_index_; // List of buffer to be emitted and PTS of frames already emitted. BufferQueue buffer_list_; std::list emitted_pts_; // - Minimum PTS of discarded frames. // - DTS of discarded frames. base::TimeDelta discarded_frames_min_pts_; std::list discarded_frames_dts_; DISALLOW_COPY_AND_ASSIGN(EsAdapterVideo); }; } // namespace mp2t } // namespace media #endif // MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_