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

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 second round of 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 // Creates and adds a new video track. Called before receiving the first
43 // frame of a given Track, adds |frame_size| and |frame_rate| to the Segment
44 // info, although individual frames passed to OnEncodedVideo() can have any
45 // frame size.
46 void AddVideoTrack(uint32_t track_number,
47 const gfx::Size& frame_size,
48 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 AddVideoTrack()ed before.
52 // |timedelta| is a delta from UTC/WebM Epoch, 2001-01-01 00:00:00.
miu 2015/07/18 00:29:39 Don't burden the client with the WebM epoch calcul
mcasas 2015/07/20 16:25:15 Done.
53 void OnEncodedVideo(uint32_t track_number,
54 const std::string& encoded_data,
55 const base::TimeDelta& timedelta,
miu 2015/07/18 00:29:39 naming: Forgot to mention last round: s/timedelta/
mcasas 2015/07/20 16:25:15 Done.
56 bool keyframe);
57
58 private:
59 friend class WebmMuxerTest;
60 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, AddVideoTrack);
61 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, Write);
62 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoEmptyAndNormalFrames);
63 FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoNormalFrames);
64
65 // IMkvWriter interface.
66 mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override;
67 mkvmuxer::int64 Position() const override;
68 mkvmuxer::int32 Position(mkvmuxer::int64 position) override;
69 bool Seekable() const override;
70 void ElementStartNotify(mkvmuxer::uint64 element_id,
71 mkvmuxer::int64 position) override;
72
73 // Used to DCHECK that we are called on the correct thread.
74 base::ThreadChecker thread_checker_;
75
76 // Callback to dump written data as being called by libwebm.
77 const WriteDataCB write_data_callback_;
78
79 // Rolling counter of the position in bytes of the written goo.
80 base::CheckedNumeric<mkvmuxer::int64> position_;
81
82 // Owned pointer to the MkvMuxer active element.
83 const scoped_ptr<mkvmuxer::Segment> segment_;
84
85 DISALLOW_COPY_AND_ASSIGN(WebmMuxer);
86 };
87
88 } // namespace media
89
90 #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