Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / formats / mp2t / es_adapter_video.h
blobf2311694aa8e664d05b9b60f7b9ed86e1c2eb869
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_
8 #include <deque>
9 #include <list>
10 #include <utility>
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 #include "media/base/stream_parser_buffer.h"
18 namespace media {
20 class VideoDecoderConfig;
22 namespace mp2t {
24 // Some constraints of the MSE spec are not necessarily met by video streams
25 // inside an Mpeg2 TS stream.
26 // The goal of the ES adapter is to modify the incoming buffers to meet these
27 // constraints, e.g.
28 // - get the frame duration,
29 // - replace the leading non-key frames by the first key frame to avoid
30 // creating a hole in the video timeline.
31 class MEDIA_EXPORT EsAdapterVideo {
32 public:
33 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB;
34 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB;
36 EsAdapterVideo(
37 const NewVideoConfigCB& new_video_config_cb,
38 const EmitBufferCB& emit_buffer_cb);
39 ~EsAdapterVideo();
41 // Force the emission of the pending video buffers.
42 void Flush();
44 // Reset the ES adapter to its initial state.
45 void Reset();
47 // Provide the configuration that applies to the upcoming video buffers.
48 void OnConfigChanged(const VideoDecoderConfig& video_decoder_config);
50 // Provide a new video buffer.
51 // Returns true when successful.
52 bool OnNewBuffer(
53 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer);
55 private:
56 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
57 typedef std::pair<int64, VideoDecoderConfig> ConfigEntry;
59 void ProcessPendingBuffers(bool flush);
61 // Return the PTS of the frame that comes just after |current_pts| in
62 // presentation order. Return kNoTimestamp() if not found.
63 base::TimeDelta GetNextFramePts(base::TimeDelta current_pts);
65 // Replace the leading non key frames by |stream_parser_buffer|
66 // (this one must be a key frame).
67 void ReplaceDiscardedFrames(
68 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer);
70 NewVideoConfigCB new_video_config_cb_;
71 EmitBufferCB emit_buffer_cb_;
73 bool has_valid_config_;
74 bool has_valid_frame_;
76 // Duration of the last video frame.
77 base::TimeDelta last_frame_duration_;
79 // Association between a video config and a buffer index.
80 std::list<ConfigEntry> config_list_;
82 // Global index of the first buffer in |buffer_list_|.
83 int64 buffer_index_;
85 // List of buffer to be emitted and PTS of frames already emitted.
86 BufferQueue buffer_list_;
87 std::list<base::TimeDelta> emitted_pts_;
89 // Minimum PTS/DTS since the last Reset.
90 bool has_valid_initial_timestamp_;
91 base::TimeDelta min_pts_;
92 DecodeTimestamp min_dts_;
94 // Number of frames to replace with the first valid key frame.
95 int discarded_frame_count_;
97 DISALLOW_COPY_AND_ASSIGN(EsAdapterVideo);
100 } // namespace mp2t
101 } // namespace media
103 #endif // MEDIA_FORMATS_MP2T_ES_ADAPTER_VIDEO_H_