OLD | NEW |
---|---|
(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 CHROME_BROWSER_CHROMEOS_WEBM_ENCODER_H_ | |
6 #define CHROME_BROWSER_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 "chrome/browser/chromeos/ebml_writer.h" | |
14 | |
15 extern "C" { | |
16 #define VPX_CODEC_DISABLE_COMPAT 1 | |
17 #include "third_party/libvpx/libvpx.h" | |
18 } | |
19 | |
20 class FilePath; | |
21 class SkBitmap; | |
22 | |
23 namespace chromeos { | |
24 | |
25 // WebM encoder using libvpx. Currently only supports one-pass, constant bitrate | |
26 // encoding of short files consisting of a single video track. Seek info and | |
27 // cues are not supported, so generated .webm file does not strictly adhere to | |
28 // WebM standard (http://www.webmproject.org/code/specs/container/). | |
29 class WebmEncoder { | |
30 public: | |
31 // Create new instance for writing to |output_path|. If |realtime| is |true|, | |
32 // uses realtime deadline, otherwise - "good quality" deadline. | |
33 WebmEncoder(const FilePath& output_path, unsigned bitrate, bool realtime); | |
34 | |
35 // Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS | |
36 // |fps_n/fps_d|. Must be called on a thread that allows IO. | |
Nikita (slow)
2012/07/18 16:23:05
nit: allows disk IO
Ivan Korotkov
2012/07/20 09:09:29
Done.
| |
37 void EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d); | |
38 | |
39 private: | |
40 // Write global WebM header and starts a single video track. | |
Nikita (slow)
2012/07/18 16:23:05
nit: Writes
Ivan Korotkov
2012/07/20 09:09:29
Done.
| |
41 void WriteWebmHeader(); | |
42 // Writes VPX packet to output file. | |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
Ivan Korotkov
2012/07/20 09:09:29
Done.
| |
43 void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet); | |
44 // Finished video track and closes output file. | |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
nit: Finishes
Ivan Korotkov
2012/07/20 09:09:29
Done.
| |
45 void WriteWebmFooter(); | |
46 | |
47 // Starts a new WebM sub-element of given type. Those can be nested. | |
48 void StartSubElement(unsigned long class_id); | |
49 // Closes current top-level sub-element. | |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
Ivan Korotkov
2012/07/20 09:09:29
Done.
| |
50 void EndSubElement(); | |
51 | |
52 // libmkv callbacks. | |
53 void EbmlWrite(const void* buffer, unsigned long len); | |
54 void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len); | |
55 | |
56 template <typename T> | |
57 void EbmlSerializeHelper(const T* buffer, unsigned long len); | |
58 | |
59 // Video dimensions and FPS. | |
60 size_t width_; | |
61 size_t height_; | |
62 vpx_rational_t fps_; | |
63 | |
64 // Single I420 frame data. | |
65 scoped_array<uint8> yuv_frame_; | |
66 | |
67 // VPX config in use. | |
68 vpx_codec_enc_cfg_t config_; | |
69 | |
70 // VPX parameters. | |
71 unsigned bitrate_; | |
72 unsigned long deadline_; | |
73 | |
74 // EbmlWriter context. | |
75 EbmlGlobal ebml_writer_; | |
76 | |
77 // Stack with start offsets of currently open sub-elements. | |
78 std::stack<long int> ebml_sub_elements_; | |
79 | |
80 FilePath output_path_; | |
81 FILE* output_; | |
82 }; | |
83 | |
84 } // namespace chromeos | |
85 | |
86 #endif // CHROME_BROWSER_CHROMEOS_WEBM_ENCODER_H_ | |
OLD | NEW |