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

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

Issue 1384483005: MediaStream Recorder: Support VP9 encoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sandersd@ comments Created 5 years, 2 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/video_track_recorder_unittest.cc ('k') | media/capture/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_FILTERS_LIBWEBM_MUXER_H_ 5 #ifndef MEDIA_FILTERS_LIBWEBM_MUXER_H_
6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_ 6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_
7 7
8 #include <set>
9
10 #include "base/callback.h" 8 #include "base/callback.h"
11 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
12 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
13 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h" 12 #include "base/time/time.h"
15 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
14 #include "media/base/video_codecs.h"
16 #include "third_party/libwebm/source/mkvmuxer.hpp" 15 #include "third_party/libwebm/source/mkvmuxer.hpp"
17 16
18 namespace gfx { 17 namespace gfx {
19 class Size; 18 class Size;
20 } // namespace gfx 19 } // namespace gfx
21 20
22 namespace media { 21 namespace media {
23 22
24 class VideoFrame; 23 class VideoFrame;
25 24
26 // Adapter class to manage a WebM container [1], a simplified version of a 25 // Adapter class to manage a WebM container [1], a simplified version of a
27 // Matroska container [2], composed of an EBML header, and a single Segment 26 // Matroska container [2], composed of an EBML header, and a single Segment
28 // including at least a Track Section and a number of SimpleBlocks each 27 // including at least a Track Section and a number of SimpleBlocks each
29 // containing a single encoded video frame. WebM container has no Trailer. 28 // containing a single encoded video frame. WebM container has no Trailer.
30 // Clients will push encoded VPx video frames one by one via OnEncodedVideo(). 29 // Clients will push encoded VPx video frames one by one via OnEncodedVideo().
31 // libwebm will eventually ping the WriteDataCB passed on contructor with the 30 // libwebm will eventually ping the WriteDataCB passed on contructor with the
32 // wrapped encoded data. 31 // wrapped encoded data.
33 // WebmMuxer is designed for single thread use throughout. 32 // WebmMuxer is designed for single thread use throughout.
34 // [1] http://www.webmproject.org/docs/container/ 33 // [1] http://www.webmproject.org/docs/container/
35 // [2] http://www.matroska.org/technical/specs/index.html 34 // [2] http://www.matroska.org/technical/specs/index.html
36 // TODO(mcasas): Add support for Audio muxing. 35 // TODO(mcasas): Add support for Audio muxing.
37 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { 36 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) {
38 public: 37 public:
39 // Callback to be called when WebmMuxer is ready to write a chunk of data, 38 // Callback to be called when WebmMuxer is ready to write a chunk of data,
40 // either any file header or a SingleBlock. 39 // either any file header or a SingleBlock.
41 using WriteDataCB = base::Callback<void(base::StringPiece)>; 40 using WriteDataCB = base::Callback<void(base::StringPiece)>;
42 41
43 explicit WebmMuxer(const WriteDataCB& write_data_callback); 42 // |codec| can be VP8 or VP9 and should coincide with whatever is sent in
43 // OnEncodedVideo().
44 WebmMuxer(VideoCodec codec, const WriteDataCB& write_data_callback);
44 ~WebmMuxer() override; 45 ~WebmMuxer() override;
45 46
46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. 47 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment.
47 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, 48 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame,
48 scoped_ptr<std::string> encoded_data, 49 scoped_ptr<std::string> encoded_data,
49 base::TimeTicks timestamp, 50 base::TimeTicks timestamp,
50 bool is_key_frame); 51 bool is_key_frame);
51 52
52 private: 53 private:
53 friend class WebmMuxerTest; 54 friend class WebmMuxerTest;
54 55
55 // Creates and adds a new video track. Called upon receiving the first 56 // Creates and adds a new video track. Called upon receiving the first
56 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment 57 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment
57 // info, although individual frames passed to OnEncodedVideo() can have any 58 // info, although individual frames passed to OnEncodedVideo() can have any
58 // frame size. 59 // frame size.
59 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); 60 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate);
60 61
61 // IMkvWriter interface. 62 // IMkvWriter interface.
62 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; 63 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
63 mkvmuxer::int64 Position() const override; 64 mkvmuxer::int64 Position() const override;
64 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; 65 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
65 bool Seekable() const override; 66 bool Seekable() const override;
66 void ElementStartNotify(mkvmuxer::uint64 element_id, 67 void ElementStartNotify(mkvmuxer::uint64 element_id,
67 mkvmuxer::int64 position) override; 68 mkvmuxer::int64 position) override;
68 69
69 // Used to DCHECK that we are called on the correct thread. 70 // Used to DCHECK that we are called on the correct thread.
70 base::ThreadChecker thread_checker_; 71 base::ThreadChecker thread_checker_;
71 72
73 // Video Codec configured: VP9 if true, otherwise VP8 is used by default.
74 const bool use_vp9_;
75
72 // A caller-side identifier to interact with |segment_|, initialised upon 76 // A caller-side identifier to interact with |segment_|, initialised upon
73 // first frame arrival by AddVideoTrack(). 77 // first frame arrival by AddVideoTrack().
74 uint64_t track_index_; 78 uint64_t track_index_;
75 79
76 // Origin of times for frame timestamps. 80 // Origin of times for frame timestamps.
77 base::TimeTicks first_frame_timestamp_; 81 base::TimeTicks first_frame_timestamp_;
78 82
79 // Callback to dump written data as being called by libwebm. 83 // Callback to dump written data as being called by libwebm.
80 const WriteDataCB write_data_callback_; 84 const WriteDataCB write_data_callback_;
81 85
82 // Rolling counter of the position in bytes of the written goo. 86 // Rolling counter of the position in bytes of the written goo.
83 base::CheckedNumeric<mkvmuxer::int64> position_; 87 base::CheckedNumeric<mkvmuxer::int64> position_;
84 88
85 // The MkvMuxer active element. 89 // The MkvMuxer active element.
86 mkvmuxer::Segment segment_; 90 mkvmuxer::Segment segment_;
87 91
88 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); 92 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
89 }; 93 };
90 94
91 } // namespace media 95 } // namespace media
92 96
93 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ 97 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/video_track_recorder_unittest.cc ('k') | media/capture/webm_muxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698