OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MUXERS_WEBM_MUXER_H_ | 5 #ifndef MEDIA_MUXERS_WEBM_MUXER_H_ |
6 #define MEDIA_MUXERS_WEBM_MUXER_H_ | 6 #define MEDIA_MUXERS_WEBM_MUXER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
| 11 #include <memory> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/numerics/safe_math.h" | 15 #include "base/numerics/safe_math.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "base/timer/elapsed_timer.h" | 19 #include "base/timer/elapsed_timer.h" |
20 #include "media/base/media_export.h" | 20 #include "media/base/media_export.h" |
21 #include "media/base/video_codecs.h" | 21 #include "media/base/video_codecs.h" |
22 #include "third_party/libwebm/source/mkvmuxer.hpp" | 22 #include "third_party/libwebm/source/mkvmuxer.hpp" |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
(...skipping 26 matching lines...) Expand all Loading... |
51 // OnEncodedVideo(). | 51 // OnEncodedVideo(). |
52 WebmMuxer(VideoCodec codec, | 52 WebmMuxer(VideoCodec codec, |
53 bool has_video_, | 53 bool has_video_, |
54 bool has_audio_, | 54 bool has_audio_, |
55 const WriteDataCB& write_data_callback); | 55 const WriteDataCB& write_data_callback); |
56 ~WebmMuxer() override; | 56 ~WebmMuxer() override; |
57 | 57 |
58 // Functions to add video and audio frames with |encoded_data.data()| | 58 // Functions to add video and audio frames with |encoded_data.data()| |
59 // to WebM Segment. | 59 // to WebM Segment. |
60 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 60 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, |
61 scoped_ptr<std::string> encoded_data, | 61 std::unique_ptr<std::string> encoded_data, |
62 base::TimeTicks timestamp, | 62 base::TimeTicks timestamp, |
63 bool is_key_frame); | 63 bool is_key_frame); |
64 void OnEncodedAudio(const media::AudioParameters& params, | 64 void OnEncodedAudio(const media::AudioParameters& params, |
65 scoped_ptr<std::string> encoded_data, | 65 std::unique_ptr<std::string> encoded_data, |
66 base::TimeTicks timestamp); | 66 base::TimeTicks timestamp); |
67 | 67 |
68 void Pause(); | 68 void Pause(); |
69 void Resume(); | 69 void Resume(); |
70 | 70 |
71 private: | 71 private: |
72 friend class WebmMuxerTest; | 72 friend class WebmMuxerTest; |
73 | 73 |
74 // Methods for creating and adding video and audio tracks, called upon | 74 // Methods for creating and adding video and audio tracks, called upon |
75 // receiving the first frame of a given Track. | 75 // receiving the first frame of a given Track. |
76 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment | 76 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment |
77 // info, although individual frames passed to OnEncodedVideo() can have any | 77 // info, although individual frames passed to OnEncodedVideo() can have any |
78 // frame size. | 78 // frame size. |
79 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); | 79 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); |
80 void AddAudioTrack(const media::AudioParameters& params); | 80 void AddAudioTrack(const media::AudioParameters& params); |
81 | 81 |
82 // IMkvWriter interface. | 82 // IMkvWriter interface. |
83 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; | 83 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; |
84 mkvmuxer::int64 Position() const override; | 84 mkvmuxer::int64 Position() const override; |
85 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; | 85 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; |
86 bool Seekable() const override; | 86 bool Seekable() const override; |
87 void ElementStartNotify(mkvmuxer::uint64 element_id, | 87 void ElementStartNotify(mkvmuxer::uint64 element_id, |
88 mkvmuxer::int64 position) override; | 88 mkvmuxer::int64 position) override; |
89 | 89 |
90 // Helper to simplify saving frames. | 90 // Helper to simplify saving frames. |
91 void AddFrame(scoped_ptr<std::string> encoded_data, | 91 void AddFrame(std::unique_ptr<std::string> encoded_data, |
92 uint8_t track_index, | 92 uint8_t track_index, |
93 base::TimeDelta timestamp, | 93 base::TimeDelta timestamp, |
94 bool is_key_frame); | 94 bool is_key_frame); |
95 | 95 |
96 // Used to DCHECK that we are called on the correct thread. | 96 // Used to DCHECK that we are called on the correct thread. |
97 base::ThreadChecker thread_checker_; | 97 base::ThreadChecker thread_checker_; |
98 | 98 |
99 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. | 99 // Video Codec configured: VP9 if true, otherwise VP8 is used by default. |
100 const bool use_vp9_; | 100 const bool use_vp9_; |
101 | 101 |
102 // Caller-side identifiers to interact with |segment_|, initialised upon | 102 // Caller-side identifiers to interact with |segment_|, initialised upon |
103 // first frame arrival to Add{Video, Audio}Track(). | 103 // first frame arrival to Add{Video, Audio}Track(). |
104 uint8_t video_track_index_; | 104 uint8_t video_track_index_; |
105 uint8_t audio_track_index_; | 105 uint8_t audio_track_index_; |
106 | 106 |
107 // Origin of times for frame timestamps. | 107 // Origin of times for frame timestamps. |
108 base::TimeTicks first_frame_timestamp_video_; | 108 base::TimeTicks first_frame_timestamp_video_; |
109 base::TimeTicks first_frame_timestamp_audio_; | 109 base::TimeTicks first_frame_timestamp_audio_; |
110 base::TimeDelta most_recent_timestamp_; | 110 base::TimeDelta most_recent_timestamp_; |
111 | 111 |
112 // Variables to measure and accumulate, respectively, the time in pause state. | 112 // Variables to measure and accumulate, respectively, the time in pause state. |
113 scoped_ptr<base::ElapsedTimer> elapsed_time_in_pause_; | 113 std::unique_ptr<base::ElapsedTimer> elapsed_time_in_pause_; |
114 base::TimeDelta total_time_in_pause_; | 114 base::TimeDelta total_time_in_pause_; |
115 | 115 |
116 // TODO(ajose): Change these when support is added for multiple tracks. | 116 // TODO(ajose): Change these when support is added for multiple tracks. |
117 // http://crbug.com/528523 | 117 // http://crbug.com/528523 |
118 const bool has_video_; | 118 const bool has_video_; |
119 const bool has_audio_; | 119 const bool has_audio_; |
120 | 120 |
121 // Callback to dump written data as being called by libwebm. | 121 // Callback to dump written data as being called by libwebm. |
122 const WriteDataCB write_data_callback_; | 122 const WriteDataCB write_data_callback_; |
123 | 123 |
124 // Rolling counter of the position in bytes of the written goo. | 124 // Rolling counter of the position in bytes of the written goo. |
125 base::CheckedNumeric<mkvmuxer::int64> position_; | 125 base::CheckedNumeric<mkvmuxer::int64> position_; |
126 | 126 |
127 // The MkvMuxer active element. | 127 // The MkvMuxer active element. |
128 mkvmuxer::Segment segment_; | 128 mkvmuxer::Segment segment_; |
129 | 129 |
130 // Hold on to all encoded video frames to dump them with and when audio is | 130 // Hold on to all encoded video frames to dump them with and when audio is |
131 // received, if expected, since WebM headers can only be written once. | 131 // received, if expected, since WebM headers can only be written once. |
132 struct EncodedVideoFrame { | 132 struct EncodedVideoFrame { |
133 EncodedVideoFrame(scoped_ptr<std::string> data, | 133 EncodedVideoFrame(std::unique_ptr<std::string> data, |
134 base::TimeTicks timestamp, | 134 base::TimeTicks timestamp, |
135 bool is_keyframe); | 135 bool is_keyframe); |
136 ~EncodedVideoFrame(); | 136 ~EncodedVideoFrame(); |
137 | 137 |
138 scoped_ptr<std::string> data; | 138 std::unique_ptr<std::string> data; |
139 base::TimeTicks timestamp; | 139 base::TimeTicks timestamp; |
140 bool is_keyframe; | 140 bool is_keyframe; |
141 | 141 |
142 private: | 142 private: |
143 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame); | 143 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame); |
144 }; | 144 }; |
145 std::deque<scoped_ptr<EncodedVideoFrame>> encoded_frames_queue_; | 145 std::deque<std::unique_ptr<EncodedVideoFrame>> encoded_frames_queue_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); | 147 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
148 }; | 148 }; |
149 | 149 |
150 } // namespace media | 150 } // namespace media |
151 | 151 |
152 #endif // MEDIA_MUXERS_WEBM_MUXER_H_ | 152 #endif // MEDIA_MUXERS_WEBM_MUXER_H_ |
OLD | NEW |