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

Side by Side Diff: media/webm/chromeos/webm_encoder.h

Issue 10784037: [cros] Implement WebM encoder/muxer for animated avatar capture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_WEBM_CHROMEOS_WEBM_ENCODER_H_
6 #define MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_
7
8 #include <stack>
9 #include <stdio.h>
10
11 #include "base/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/media_export.h"
14 #include "media/webm/chromeos/ebml_writer.h"
15
16 extern "C" {
17 #define VPX_CODEC_DISABLE_COMPAT 1
18 #include "third_party/libvpx/libvpx.h"
19 }
20
21 class FilePath;
22 class SkBitmap;
23
24 namespace media {
25
26 namespace chromeos {
27
28 // WebM encoder using libvpx. Currently only supports one-pass, constant bitrate
29 // encoding of short files consisting of a single video track. Seek info and
30 // cues are not supported, so generated .webm file does not strictly adhere to
31 // WebM standard (http://www.webmproject.org/code/specs/container/).
32 class MEDIA_EXPORT WebmEncoder {
33 public:
34 // Create new instance for writing to |output_path|. If |realtime| is |true|,
35 // uses realtime deadline, otherwise - "good quality" deadline.
36 WebmEncoder(const FilePath& output_path, int bitrate, bool realtime);
37
38 // Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS
39 // |fps_n/fps_d|. Must be called on a thread that allows disk IO.
40 // Returns |true| iff encoding and writing to file is successful.
41 bool EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d);
42
43 private:
44 // Writes global WebM header and starts a single video track. Returns |false|
45 // if there is an error opening file for writing.
46 bool WriteWebmHeader();
47
48 // Writes VPX packet to output file.
49 void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet);
50
51 // Finishes video track and closes output file. Returns |false| if there is
52 // an error closing file.
53 bool WriteWebmFooter();
54
55 // Starts a new WebM sub-element of given type. Those can be nested.
56 void StartSubElement(unsigned long class_id);
57
58 // Closes current top-level sub-element.
59 void EndSubElement();
60
61 // libmkv callbacks.
62 void EbmlWrite(const void* buffer, unsigned long len);
63 void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len);
64
65 template <typename T>
66 void EbmlSerializeHelper(const T* buffer, unsigned long len);
67
68 // Video dimensions and FPS.
69 size_t width_;
70 size_t height_;
71 vpx_rational_t fps_;
72
73 // Single I420 frame data.
74 scoped_array<uint8> yuv_frame_;
75
76 // VPX config in use.
77 vpx_codec_enc_cfg_t config_;
78
79 // VPX parameters.
80 int bitrate_;
81 unsigned long deadline_;
82
83 // EbmlWriter context.
84 EbmlGlobal ebml_writer_;
85
86 // Stack with start offsets of currently open sub-elements.
87 std::stack<long int> ebml_sub_elements_;
88
89 FilePath output_path_;
90 FILE* output_;
91
92 DISALLOW_COPY_AND_ASSIGN(WebmEncoder);
93 };
94
95 } // namespace chromeos
96
97 } // namespace media
98
99 #endif // MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698