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.
5 #ifndef MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_
6 #define MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_
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"
18 class StreamParserBuffer
;
19 class VideoDecoderConfig
;
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
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
{
32 typedef base::Callback
<void(const VideoDecoderConfig
&)> NewVideoConfigCB
;
33 typedef base::Callback
<void(scoped_refptr
<StreamParserBuffer
>)> EmitBufferCB
;
36 const NewVideoConfigCB
& new_video_config_cb
,
37 const EmitBufferCB
& emit_buffer_cb
);
40 // Force the emission of the pending video buffers.
43 // Reset the ES adapter to its initial state.
46 // Provide the configuration that applies to the upcoming video buffers.
47 void OnConfigChanged(const VideoDecoderConfig
& video_decoder_config
);
49 // Provide a new video buffer.
51 const scoped_refptr
<StreamParserBuffer
>& stream_parser_buffer
);
54 typedef std::deque
<scoped_refptr
<StreamParserBuffer
> > BufferQueue
;
55 typedef std::pair
<int64
, VideoDecoderConfig
> ConfigEntry
;
57 void ProcessPendingBuffers(bool flush
);
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
);
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
);
68 NewVideoConfigCB new_video_config_cb_
;
69 EmitBufferCB emit_buffer_cb_
;
71 bool has_valid_config_
;
72 bool has_valid_frame_
;
74 // Duration of the last video frame.
75 base::TimeDelta last_frame_duration_
;
77 // Association between a video config and a buffer index.
78 std::list
<ConfigEntry
> config_list_
;
80 // Global index of the first buffer in |buffer_list_|.
83 // List of buffer to be emitted and PTS of frames already emitted.
84 BufferQueue buffer_list_
;
85 std::list
<base::TimeDelta
> emitted_pts_
;
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_
;
92 DISALLOW_COPY_AND_ASSIGN(EsAdapterVideo
);
98 #endif // MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_