Chromium Code Reviews| Index: media/capture/webm_muxer.h |
| diff --git a/media/capture/webm_muxer.h b/media/capture/webm_muxer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..96e31734ebecd18f0608a9f341e904aa6e299735 |
| --- /dev/null |
| +++ b/media/capture/webm_muxer.h |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
| +#define MEDIA_FILTERS_LIBWEBM_MUXER_H_ |
| + |
| +#include <set> |
| + |
| +#include "base/callback.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/numerics/safe_math.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "base/time/time.h" |
| +#include "media/base/media_export.h" |
| +#include "third_party/libwebm/source/mkvmuxer.hpp" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace media { |
| + |
| +// Adapter class to manage a WebM container, a simplified version of a Matroska |
| +// container [1], composed of an EBML header, and a single Segment including |
| +// at least a Track Section and a number of SimpleBlocks each containing a |
| +// single encoded video frame. WebM container has no Trailer. |
| +// Clients will push encoded VPx video frames one by one via OnEncodedVideo() |
| +// with indication of the Track they belong to, and libwebm will eventually ping |
| +// the WriteDataCB passed on contructor with the wrapped encoded data. All |
| +// operations must happen in a single thread, where WebmMuxer is created and |
| +// destroyed. |
| +// [1] http://www.matroska.org/technical/specs/index.html |
| +// TODO(mcasas): Add support for Audio muxing. |
| +class MEDIA_EXPORT WebmMuxer : public mkvmuxer::IMkvWriter { |
| + public: |
| + // Callback to be called when WebmMuxer is ready to write a chunk of data, |
| + // either any file header or a SingleBlock. The chunk is described as a byte |
| + // array and a byte length. |
| + typedef base::Callback<void(const char*, size_t)> WriteDataCB; |
| + |
| + explicit WebmMuxer(const WriteDataCB& write_data_callback); |
| + ~WebmMuxer() override; |
| + |
| + // Adds a frame with |encoded_data.data()| to WebM Segment. |track_number| is |
| + // a caller-side identifier. A new VideoTrack is created when |track_number| |
| + // is seen for the first time, with |frame_size| and |frame_rate| indication, |
| + // although individual encoded video frames can have different format. |
| + // |timedelta| is microseconds from UTC/WebM Epoch, 2001-01-01 00:00:00. |
| + void OnEncodedVideo(uint32_t track_number, |
| + const std::string& encoded_data, |
| + 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.
|
| + bool keyframe, |
| + 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
|
| + double frame_rate); |
| + |
| + private: |
| + friend class WebmMuxerTest; |
| + FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, Write); |
| + FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoEmptyAndNormalFrames); |
| + FRIEND_TEST_ALL_PREFIXES(WebmMuxerTest, OnEncodedVideoNormalFrames); |
| + |
| + // Creates and adds a new video track. Called when receiving the first frame, |
| + // adds |frame_size| and |frame_rate| to the Segment info. |track_numer| can't |
| + // be zero. |
| + bool AddVideoTrack(uint32_t track_number, |
| + const gfx::Size& frame_size, |
| + double frame_rate); |
| + |
| + // IMkvWriter interface. |
| + mkvmuxer::int32 Write(const void* buf, mkvmuxer::uint32 len) override; |
| + mkvmuxer::int64 Position() const override; |
| + mkvmuxer::int32 Position(mkvmuxer::int64 position) override; |
| + bool Seekable() const override; |
| + void ElementStartNotify(mkvmuxer::uint64 element_id, |
| + mkvmuxer::int64 position) override; |
| + |
| + // Used to DCHECK that we are called on the correct thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + // Callback to dump written data as being called by libwebm. |
| + const WriteDataCB write_data_callback_; |
| + |
| + // Rolling counter of the position in bytes of the written goo. |
| + base::CheckedNumeric<mkvmuxer::int64> position_; |
| + |
| + // Owned pointer to the MkvMuxer active element. |
| + const scoped_ptr<mkvmuxer::Segment> segment_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebmMuxer); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_FILTERS_LIBWEBM_MUXER_H_ |