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

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

Issue 1225123006: media/capture: Adding WebmMuxer class and unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@m_crbug262211__MSRecorder__2__libwebm_reland_in_third_party
Patch Set: miu@s comments Created 5 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_FILTERS_LIBWEBM_MUXER_H_
6 #define MEDIA_FILTERS_LIBWEBM_MUXER_H_
7
8 #include <set>
9
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/numerics/safe_math.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h"
15 #include "media/base/media_export.h"
16 #include "third_party/libwebm/source/mkvmuxer.hpp"
17 #include "ui/gfx/geometry/size.h"
18
19 namespace media {
20
21 // Adapter class to manage a WebM container, a simplified version of a Matroska
22 // container [1], composed of an EBML header, and a single Segment including
23 // at least a Track Section and a number of SimpleBlocks each containing a
24 // single encoded video frame. WebM container has no Trailer.
25 // Clients will push encoded VPx video frames one by one via OnEncodedVideo()
26 // with indication of the Track they belong to, and libwebm will eventually ping
27 // the WriteDataCB passed on contructor with the wrapped encoded data. All
28 // operations must happen in a single thread, where WebmMuxer is created and
29 // destroyed.
30 // [1] http://www.matroska.org/technical/specs/index.html
31 // TODO(mcasas): Add support for Audio muxing.
32 class MEDIA_EXPORT WebmMuxer : public mkvmuxer::IMkvWriter {
33 public:
34 // Callback to be called when WebmMuxer is ready to write a chunk of data,
35 // either any file header or a SingleBlock. The chunk is described as a byte
36 // array and a byte length.
37 typedef base::Callback<void(const char*, size_t)> WriteDataCB;
38
39 explicit WebmMuxer(const WriteDataCB& write_data_callback);
40 ~WebmMuxer() override;
41
42 // Adds a frame with |encoded_data.data()| to WebM Segment. |track_number| is
43 // a caller-side identifier. A new VideoTrack is created when |track_number|
44 // is seen for the first time, with |frame_size| and |frame_rate| indication,
45 // although individual encoded video frames can have different format.
46 // |timedelta| is microseconds from UTC/WebM Epoch, 2001-01-01 00:00:00.
47 void OnEncodedVideo(uint32_t track_number,
48 const std::string& encoded_data,
49 const base::TimeDelta& timedelta_us,
miu 2015/07/17 22:23:19 naming: No _us suffix here, since that's an abstra
mcasas 2015/07/18 00:05:22 Done.
50 bool keyframe,
51 const gfx::Size& frame_size,
miu 2015/07/17 22:23:19 Instead of placing a burden on the caller to pass
mcasas 2015/07/18 00:05:22 Yeps, exactly my question before, got lost in the
52 double frame_rate);
53
54 private:
55 friend class WebmMuxerTest;
56 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, Write);
57 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoEmptyAndNormalFrames);
58 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoNormalFrames);
59
60 // Creates and adds a new video track. Called when receiving the first frame,
61 // adds |frame_size| and |frame_rate| to the Segment info. |track_numer| can't
62 // be zero.
63 bool AddVideoTrack(uint32_t track_number,
64 const gfx::Size& frame_size,
65 double frame_rate);
66
67 // IMkvWriter interface.
68 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
69 mkvmuxer::int64 Position() const override;
70 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
71 bool Seekable() const override;
72 void ElementStartNotify(mkvmuxer::uint64 element_id,
73 mkvmuxer::int64 position) override;
74
75 // Used to DCHECK that we are called on the correct thread.
76 base::ThreadChecker thread_checker_;
77
78 // Callback to dump written data as being called by libwebm.
79 const WriteDataCB write_data_callback_;
80
81 // Rolling counter of the position in bytes of the written goo.
82 base::CheckedNumeric<mkvmuxer::int64> position_;
83
84 // Owned pointer to the MkvMuxer active element.
85 const scoped_ptr<mkvmuxer::Segment> segment_;
86
87 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
88 };
89
90 } // namespace media
91
92 #endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_
OLDNEW
« no previous file with comments | « media/DEPS ('k') | media/capture/webm_muxer.cc » ('j') | media/capture/webm_muxer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698