Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: media/muxers/webm_muxer.h

Issue 2633623002: MediaRecorder: handle libwebm::Segment::AddFrame() errors and wire up to Blink (Closed)
Patch Set: I can haz moar testing? Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/media/media_recorder_handler_unittest.cc ('k') | media/muxers/webm_muxer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in 60 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in
61 // OnEncodedVideo(). 61 // OnEncodedVideo().
62 WebmMuxer(VideoCodec codec, 62 WebmMuxer(VideoCodec codec,
63 bool has_video_, 63 bool has_video_,
64 bool has_audio_, 64 bool has_audio_,
65 const WriteDataCB& write_data_callback); 65 const WriteDataCB& write_data_callback);
66 ~WebmMuxer() override; 66 ~WebmMuxer() override;
67 67
68 // Functions to add video and audio frames with |encoded_data.data()| 68 // Functions to add video and audio frames with |encoded_data.data()|
69 // to WebM Segment. 69 // to WebM Segment. Either one returns true on success.
70 void OnEncodedVideo(const VideoParameters& params, 70 bool OnEncodedVideo(const VideoParameters& params,
71 std::unique_ptr<std::string> encoded_data, 71 std::unique_ptr<std::string> encoded_data,
72 base::TimeTicks timestamp, 72 base::TimeTicks timestamp,
73 bool is_key_frame); 73 bool is_key_frame);
74 void OnEncodedAudio(const media::AudioParameters& params, 74 bool OnEncodedAudio(const media::AudioParameters& params,
75 std::unique_ptr<std::string> encoded_data, 75 std::unique_ptr<std::string> encoded_data,
76 base::TimeTicks timestamp); 76 base::TimeTicks timestamp);
77 77
78 void Pause(); 78 void Pause();
79 void Resume(); 79 void Resume();
80 80
81 void ForceOneLibWebmErrorForTesting() { force_one_libwebm_error_ = true; }
82
81 private: 83 private:
82 friend class WebmMuxerTest; 84 friend class WebmMuxerTest;
83 85
84 // Methods for creating and adding video and audio tracks, called upon 86 // Methods for creating and adding video and audio tracks, called upon
85 // receiving the first frame of a given Track. 87 // receiving the first frame of a given Track.
86 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment 88 // AddVideoTrack adds |frame_size| and |frame_rate| to the Segment
87 // info, although individual frames passed to OnEncodedVideo() can have any 89 // info, although individual frames passed to OnEncodedVideo() can have any
88 // frame size. 90 // frame size.
89 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); 91 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate);
90 void AddAudioTrack(const media::AudioParameters& params); 92 void AddAudioTrack(const media::AudioParameters& params);
91 93
92 // IMkvWriter interface. 94 // IMkvWriter interface.
93 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; 95 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
94 mkvmuxer::int64 Position() const override; 96 mkvmuxer::int64 Position() const override;
95 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; 97 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
96 bool Seekable() const override; 98 bool Seekable() const override;
97 void ElementStartNotify(mkvmuxer::uint64 element_id, 99 void ElementStartNotify(mkvmuxer::uint64 element_id,
98 mkvmuxer::int64 position) override; 100 mkvmuxer::int64 position) override;
99 101
100 // Helper to simplify saving frames. 102 // Helper to simplify saving frames. Returns true on success.
101 void AddFrame(std::unique_ptr<std::string> encoded_data, 103 bool AddFrame(std::unique_ptr<std::string> encoded_data,
102 uint8_t track_index, 104 uint8_t track_index,
103 base::TimeDelta timestamp, 105 base::TimeDelta timestamp,
104 bool is_key_frame); 106 bool is_key_frame);
105 107
106 // Used to DCHECK that we are called on the correct thread. 108 // Used to DCHECK that we are called on the correct thread.
107 base::ThreadChecker thread_checker_; 109 base::ThreadChecker thread_checker_;
108 110
109 // Video Codec configured on construction. 111 // Video Codec configured on construction.
110 const VideoCodec video_codec_; 112 const VideoCodec video_codec_;
111 113
(...skipping 17 matching lines...) Expand all
129 const bool has_audio_; 131 const bool has_audio_;
130 132
131 // Callback to dump written data as being called by libwebm. 133 // Callback to dump written data as being called by libwebm.
132 const WriteDataCB write_data_callback_; 134 const WriteDataCB write_data_callback_;
133 135
134 // Rolling counter of the position in bytes of the written goo. 136 // Rolling counter of the position in bytes of the written goo.
135 base::CheckedNumeric<mkvmuxer::int64> position_; 137 base::CheckedNumeric<mkvmuxer::int64> position_;
136 138
137 // The MkvMuxer active element. 139 // The MkvMuxer active element.
138 mkvmuxer::Segment segment_; 140 mkvmuxer::Segment segment_;
141 // Flag to force the next call to a |segment_| method to return false.
142 bool force_one_libwebm_error_;
139 143
140 // Hold on to all encoded video frames to dump them with and when audio is 144 // Hold on to all encoded video frames to dump them with and when audio is
141 // received, if expected, since WebM headers can only be written once. 145 // received, if expected, since WebM headers can only be written once.
142 struct EncodedVideoFrame { 146 struct EncodedVideoFrame {
143 EncodedVideoFrame(std::unique_ptr<std::string> data, 147 EncodedVideoFrame(std::unique_ptr<std::string> data,
144 base::TimeTicks timestamp, 148 base::TimeTicks timestamp,
145 bool is_keyframe); 149 bool is_keyframe);
146 ~EncodedVideoFrame(); 150 ~EncodedVideoFrame();
147 151
148 std::unique_ptr<std::string> data; 152 std::unique_ptr<std::string> data;
149 base::TimeTicks timestamp; 153 base::TimeTicks timestamp;
150 bool is_keyframe; 154 bool is_keyframe;
151 155
152 private: 156 private:
153 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame); 157 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedVideoFrame);
154 }; 158 };
155 std::deque<std::unique_ptr<EncodedVideoFrame>> encoded_frames_queue_; 159 std::deque<std::unique_ptr<EncodedVideoFrame>> encoded_frames_queue_;
156 160
157 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); 161 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
158 }; 162 };
159 163
160 } // namespace media 164 } // namespace media
161 165
162 #endif // MEDIA_MUXERS_WEBM_MUXER_H_ 166 #endif // MEDIA_MUXERS_WEBM_MUXER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/media_recorder_handler_unittest.cc ('k') | media/muxers/webm_muxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698