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

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

Issue 1233033002: MediaStream: Adding VideoTrackRecorder class and unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved |track_index| and timestamp mgmt from VideoTrackRecorder into WebmMuxer Created 5 years, 4 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
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> 8 #include <set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/numerics/safe_math.h" 12 #include "base/numerics/safe_math.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
17 #include "third_party/libwebm/source/mkvmuxer.hpp" 17 #include "third_party/libwebm/source/mkvmuxer.hpp"
18 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
19 19
20 namespace media { 20 namespace media {
21 21
22 class VideoFrame;
23
22 // Adapter class to manage a WebM container [1], a simplified version of a 24 // Adapter class to manage a WebM container [1], a simplified version of a
23 // Matroska container [2], composed of an EBML header, and a single Segment 25 // Matroska container [2], composed of an EBML header, and a single Segment
24 // including at least a Track Section and a number of SimpleBlocks each 26 // including at least a Track Section and a number of SimpleBlocks each
25 // containing a single encoded video frame. WebM container has no Trailer. 27 // containing a single encoded video frame. WebM container has no Trailer.
26 // Clients will push encoded VPx video frames one by one via OnEncodedVideo() 28 // Clients will push encoded VPx video frames one by one via the
27 // with indication of the Track they belong to, and libwebm will eventually ping 29 // OnEncodedVideoCB() returned by AddVideoTrack(). libwebm will eventually ping
miu 2015/08/18 02:08:35 Revert this comment w/ latest changes?
mcasas 2015/08/19 00:16:30 Done.
28 // the WriteDataCB passed on contructor with the wrapped encoded data. All 30 // the WriteDataCB passed on contructor with the wrapped encoded data. All
29 // operations must happen in a single thread, where WebmMuxer is created and 31 // operations must happen in a single thread, where WebmMuxer is created and
30 // destroyed. 32 // destroyed.
31 // [1] http://www.webmproject.org/docs/container/ 33 // [1] http://www.webmproject.org/docs/container/
32 // [2] http://www.matroska.org/technical/specs/index.html 34 // [2] http://www.matroska.org/technical/specs/index.html
33 // TODO(mcasas): Add support for Audio muxing. 35 // TODO(mcasas): Add support for Audio muxing.
34 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { 36 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) {
35 public: 37 public:
36 // 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,
37 // either any file header or a SingleBlock. The chunk is described as a byte 39 // either any file header or a SingleBlock. The chunk is described as a byte
38 // array and a byte length. 40 // array and a byte length.
39 using WriteDataCB = base::Callback<void(const base::StringPiece&)>; 41 using WriteDataCB = base::Callback<void(const base::StringPiece&)>;
40 42
41 explicit WebmMuxer(const WriteDataCB& write_data_callback); 43 explicit WebmMuxer(const WriteDataCB& write_data_callback);
42 ~WebmMuxer() override; 44 ~WebmMuxer() override;
43 45
44 // Creates and adds a new video track. Called before receiving the first 46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment.
45 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment
46 // info, although individual frames passed to OnEncodedVideo() can have any
47 // frame size. Returns the track_index to be used for OnEncodedVideo().
48 uint64_t AddVideoTrack(const gfx::Size& frame_size, double frame_rate);
49
50 // Adds a frame with |encoded_data.data()| to WebM Segment. |track_number| is
51 // a caller-side identifier and must have been provided by AddVideoTrack().
52 // TODO(mcasas): Revisit how |encoded_data| is passed once the whole recording 47 // TODO(mcasas): Revisit how |encoded_data| is passed once the whole recording
53 // chain is setup (http://crbug.com/262211). 48 // chain is setup (http://crbug.com/262211).
54 void OnEncodedVideo(uint64_t track_number, 49 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame,
55 const base::StringPiece& encoded_data, 50 const base::StringPiece& encoded_data,
56 base::TimeDelta timestamp, 51 base::TimeTicks timestamp,
57 bool keyframe); 52 bool is_key_frame);
58 53
59 private: 54 private:
60 friend class WebmMuxerTest; 55 friend class WebmMuxerTest;
61 56
57 // Creates and adds a new video track. Called upon receiving the first
58 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment
59 // info, although individual frames passed to OnEncodedVideo() can have any
60 // frame size. Returns OnEncodedVideo() callback with a |track_number| bound
61 // in the callback.
62 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate);
63
62 // IMkvWriter interface. 64 // IMkvWriter interface.
63 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; 65 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
64 mkvmuxer::int64 Position() const override; 66 mkvmuxer::int64 Position() const override;
65 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; 67 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
66 bool Seekable() const override; 68 bool Seekable() const override;
67 void ElementStartNotify(mkvmuxer::uint64 element_id, 69 void ElementStartNotify(mkvmuxer::uint64 element_id,
68 mkvmuxer::int64 position) override; 70 mkvmuxer::int64 position) override;
69 71
70 // Used to DCHECK that we are called on the correct thread. 72 // Used to DCHECK that we are called on the correct thread.
71 base::ThreadChecker thread_checker_; 73 base::ThreadChecker thread_checker_;
72 74
75 // A caller-side identifier to interact with |segment_|, initialised upon
76 // first frame arrival by AddVideoTrack().
77 uint64_t track_index_;
78
79 // Origin of times for frame timestamps.
80 base::TimeTicks first_frame_timestamp_;
81
73 // Callback to dump written data as being called by libwebm. 82 // Callback to dump written data as being called by libwebm.
74 const WriteDataCB write_data_callback_; 83 const WriteDataCB write_data_callback_;
75 84
76 // Rolling counter of the position in bytes of the written goo. 85 // Rolling counter of the position in bytes of the written goo.
77 base::CheckedNumeric<mkvmuxer::int64> position_; 86 base::CheckedNumeric<mkvmuxer::int64> position_;
78 87
79 // The MkvMuxer active element. 88 // The MkvMuxer active element.
80 mkvmuxer::Segment segment_; 89 mkvmuxer::Segment segment_;
81 90
82 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); 91 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
83 }; 92 };
84 93
85 } // namespace media 94 } // namespace media
86 95
87 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ 96 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698