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

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

Issue 1351473006: WebmMuxer-MediaRecorderHandler: thread hopping and data ownership (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@ proposal 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
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"
12 #include "base/numerics/safe_math.h" 11 #include "base/numerics/safe_math.h"
13 #include "base/strings/string_piece.h"
14 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
15 #include "base/time/time.h" 13 #include "base/time/time.h"
16 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
17 #include "third_party/libwebm/source/mkvmuxer.hpp" 15 #include "third_party/libwebm/source/mkvmuxer.hpp"
18 #include "ui/gfx/geometry/size.h" 16
17 namespace gfx {
18 class Size;
19 } // namespace gfx
19 20
20 namespace media { 21 namespace media {
21 22
22 class VideoFrame; 23 class VideoFrame;
23 24
24 // 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
25 // 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
26 // 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
27 // containing a single encoded video frame. WebM container has no Trailer. 28 // containing a single encoded video frame. WebM container has no Trailer.
28 // Clients will push encoded VPx video frames one by one via the 29 // Clients will push encoded VPx video frames one by one via OnEncodedVideo().
29 // OnEncodedVideo(). libwebm will eventually ping the WriteDataCB passed on 30 // libwebm will eventually ping the WriteDataCB passed on contructor with the
30 // contructor with the wrapped encoded data. 31 // wrapped encoded data.
31 // WebmMuxer is created/destroyed on a thread, usually the Main Render thread, 32 // WebmMuxer is created/destroyed and operates on a single thread, usually the
32 // and receives OnEncodedVideo()s on another thread, usually Render IO. 33 // Main Render thread; notably, it receives OnEncodedVideo()s on that thread.
miu 2015/09/22 04:11:08 Up to you, but the comment should either: 1. Just
mcasas 2015/09/22 16:58:41 #1 it is !
33 // [1] http://www.webmproject.org/docs/container/ 34 // [1] http://www.webmproject.org/docs/container/
34 // [2] http://www.matroska.org/technical/specs/index.html 35 // [2] http://www.matroska.org/technical/specs/index.html
35 // TODO(mcasas): Add support for Audio muxing. 36 // TODO(mcasas): Add support for Audio muxing.
36 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) { 37 class MEDIA_EXPORT WebmMuxer : public NON_EXPORTED_BASE(mkvmuxer::IMkvWriter) {
37 public: 38 public:
38 // Callback to be called when WebmMuxer is ready to write a chunk of data, 39 // Callback to be called when WebmMuxer is ready to write a chunk of data,
39 // either any file header or a SingleBlock. The chunk is described as a byte 40 // either any file header or a SingleBlock.
40 // array and a byte length. 41 using WriteDataCB = base::Callback<void(scoped_ptr<std::string> data)>;
41 using WriteDataCB = base::Callback<void(const base::StringPiece&)>;
42 42
43 explicit WebmMuxer(const WriteDataCB& write_data_callback); 43 explicit WebmMuxer(const WriteDataCB& write_data_callback);
44 ~WebmMuxer() override; 44 ~WebmMuxer() override;
45 45
46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment. 46 // Adds a |video_frame| with |encoded_data.data()| to WebM Segment.
47 // TODO(mcasas): Revisit how |encoded_data| is passed once the whole recording
48 // chain is setup (http://crbug.com/262211).
49 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, 47 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame,
50 const base::StringPiece& encoded_data, 48 scoped_ptr<std::string> encoded_data,
51 base::TimeTicks timestamp, 49 base::TimeTicks timestamp,
52 bool is_key_frame); 50 bool is_key_frame);
53 51
54 private: 52 private:
55 friend class WebmMuxerTest; 53 friend class WebmMuxerTest;
56 54
57 // Creates and adds a new video track. Called upon receiving the first 55 // 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 56 // 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 57 // info, although individual frames passed to OnEncodedVideo() can have any
60 // frame size. 58 // frame size.
61 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate); 59 void AddVideoTrack(const gfx::Size& frame_size, double frame_rate);
62 60
63 // IMkvWriter interface. 61 // IMkvWriter interface.
64 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; 62 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
65 mkvmuxer::int64 Position() const override; 63 mkvmuxer::int64 Position() const override;
66 mkvmuxer::int32 Position(mkvmuxer::int64 position) override; 64 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
67 bool Seekable() const override; 65 bool Seekable() const override;
68 void ElementStartNotify(mkvmuxer::uint64 element_id, 66 void ElementStartNotify(mkvmuxer::uint64 element_id,
69 mkvmuxer::int64 position) override; 67 mkvmuxer::int64 position) override;
70 68
71 // Used to DCHECK that we are called on the correct thread (usually IO) 69 // Used to DCHECK that we are called on the correct thread.
72 base::ThreadChecker thread_checker_; 70 base::ThreadChecker thread_checker_;
73 71
74 // A caller-side identifier to interact with |segment_|, initialised upon 72 // A caller-side identifier to interact with |segment_|, initialised upon
75 // first frame arrival by AddVideoTrack(). 73 // first frame arrival by AddVideoTrack().
76 uint64_t track_index_; 74 uint64_t track_index_;
77 75
78 // Origin of times for frame timestamps. 76 // Origin of times for frame timestamps.
79 base::TimeTicks first_frame_timestamp_; 77 base::TimeTicks first_frame_timestamp_;
80 78
81 // Callback to dump written data as being called by libwebm. 79 // Callback to dump written data as being called by libwebm.
82 const WriteDataCB write_data_callback_; 80 const WriteDataCB write_data_callback_;
83 81
84 // Rolling counter of the position in bytes of the written goo. 82 // Rolling counter of the position in bytes of the written goo.
85 base::CheckedNumeric<mkvmuxer::int64> position_; 83 base::CheckedNumeric<mkvmuxer::int64> position_;
86 84
87 // The MkvMuxer active element. 85 // The MkvMuxer active element.
88 mkvmuxer::Segment segment_; 86 mkvmuxer::Segment segment_;
89 87
90 DISALLOW_COPY_AND_ASSIGN(WebmMuxer); 88 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
91 }; 89 };
92 90
93 } // namespace media 91 } // namespace media
94 92
95 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ 93 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698