cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / webm / chromeos / webm_encoder.h
blob126c0d20758e530036af19acdba72d7154129663
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.
5 #ifndef MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_
6 #define MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_
8 #include <stdio.h>
9 #include <stack>
11 #include "base/files/file_path.h"
12 #include "media/base/media_export.h"
13 #include "media/webm/chromeos/ebml_writer.h"
15 extern "C" {
16 #define VPX_CODEC_DISABLE_COMPAT 1
17 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
18 #include "third_party/libvpx/source/libvpx/vpx/vp8cx.h"
21 class SkBitmap;
23 namespace base {
24 class FilePath;
27 namespace media {
29 namespace chromeos {
31 // WebM encoder using libvpx. Currently only supports one-pass, constant bitrate
32 // encoding of short files consisting of a single video track. Seek info and
33 // cues are not supported, so generated .webm file does not strictly adhere to
34 // WebM standard (http://www.webmproject.org/code/specs/container/).
35 class MEDIA_EXPORT WebmEncoder {
36 public:
37 // Create new instance for writing to |output_path|. If |realtime| is |true|,
38 // uses realtime deadline, otherwise - "good quality" deadline.
39 WebmEncoder(const base::FilePath& output_path, int bitrate, bool realtime);
40 ~WebmEncoder();
42 // Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS
43 // |fps_n/fps_d|. Must be called on a thread that allows disk IO.
44 // Returns |true| iff encoding and writing to file is successful.
45 bool EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d);
47 private:
48 // Writes global WebM header and starts a single video track. Returns |false|
49 // if there was an error opening file for writing.
50 bool WriteWebmHeader();
52 // Writes VPX packet to output file.
53 void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet);
55 // Finishes video track and closes output file. Returns |false| if there were
56 // any error during encoding/writing file.
57 bool WriteWebmFooter();
59 // Starts a new WebM sub-element of given type. Those can be nested.
60 void StartSubElement(unsigned long class_id);
62 // Closes current top-level sub-element.
63 void EndSubElement();
65 // libmkv callbacks.
66 void EbmlWrite(const void* buffer, unsigned long len);
67 void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len);
69 template <typename T>
70 void EbmlSerializeHelper(const T* buffer, unsigned long len);
72 // Video dimensions and FPS.
73 size_t width_;
74 size_t height_;
75 vpx_rational_t fps_;
77 // Number of frames in video.
78 size_t frame_count_;
80 // VPX config in use.
81 vpx_codec_enc_cfg_t config_;
83 // VPX parameters.
84 int bitrate_;
85 unsigned long deadline_;
87 // EbmlWriter context.
88 EbmlGlobal ebml_writer_;
90 // Stack with start offsets of currently open sub-elements.
91 std::stack<long int> ebml_sub_elements_;
93 base::FilePath output_path_;
94 FILE* output_;
96 // True if an error occured while encoding/writing to file.
97 bool has_errors_;
99 DISALLOW_COPY_AND_ASSIGN(WebmEncoder);
102 } // namespace chromeos
104 } // namespace media
106 #endif // MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_