Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / video_coding / codecs / vp9 / vp9_impl.h
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  *
10  */
11
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_
14
15 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
16
17 // VPX forward declaration
18 typedef struct vpx_codec_ctx vpx_codec_ctx_t;
19 typedef struct vpx_codec_ctx vpx_dec_ctx_t;
20 typedef struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t;
21 typedef struct vpx_image vpx_image_t;
22 typedef struct vpx_ref_frame vpx_ref_frame_t;
23 struct vpx_codec_cx_pkt;
24
25 namespace webrtc {
26
27 class VP9EncoderImpl : public VP9Encoder {
28  public:
29   VP9EncoderImpl();
30
31   virtual ~VP9EncoderImpl();
32
33   virtual int Release() OVERRIDE;
34
35   virtual int InitEncode(const VideoCodec* codec_settings,
36                          int number_of_cores,
37                          uint32_t max_payload_size) OVERRIDE;
38
39   virtual int Encode(const I420VideoFrame& input_image,
40                      const CodecSpecificInfo* codec_specific_info,
41                      const std::vector<VideoFrameType>* frame_types) OVERRIDE;
42
43   virtual int RegisterEncodeCompleteCallback(EncodedImageCallback* callback)
44   OVERRIDE;
45
46   virtual int SetChannelParameters(uint32_t packet_loss, int rtt) OVERRIDE;
47
48   virtual int SetRates(uint32_t new_bitrate_kbit, uint32_t frame_rate) OVERRIDE;
49
50  private:
51   // Call encoder initialize function and set control settings.
52   int InitAndSetControlSettings(const VideoCodec* inst);
53
54   void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
55                              const vpx_codec_cx_pkt& pkt,
56                              uint32_t timestamp);
57
58   int GetEncodedPartitions(const I420VideoFrame& input_image);
59
60   // Determine maximum target for Intra frames
61   //
62   // Input:
63   //    - optimal_buffer_size : Optimal buffer size
64   // Return Value             : Max target size for Intra frames represented as
65   //                            percentage of the per frame bandwidth
66   uint32_t MaxIntraTarget(uint32_t optimal_buffer_size);
67
68   EncodedImage encoded_image_;
69   EncodedImageCallback* encoded_complete_callback_;
70   VideoCodec codec_;
71   bool inited_;
72   int64_t timestamp_;
73   uint16_t picture_id_;
74   int cpu_speed_;
75   uint32_t rc_max_intra_target_;
76   vpx_codec_ctx_t* encoder_;
77   vpx_codec_enc_cfg_t* config_;
78   vpx_image_t* raw_;
79 };
80
81
82 class VP9DecoderImpl : public VP9Decoder {
83  public:
84   VP9DecoderImpl();
85
86   virtual ~VP9DecoderImpl();
87
88   virtual int InitDecode(const VideoCodec* inst, int number_of_cores) OVERRIDE;
89
90   virtual int Decode(const EncodedImage& input_image,
91                      bool missing_frames,
92                      const RTPFragmentationHeader* fragmentation,
93                      const CodecSpecificInfo* codec_specific_info,
94                      int64_t /*render_time_ms*/) OVERRIDE;
95
96   virtual int RegisterDecodeCompleteCallback(DecodedImageCallback* callback)
97   OVERRIDE;
98
99   virtual int Release() OVERRIDE;
100
101   virtual int Reset() OVERRIDE;
102
103  private:
104   int ReturnFrame(const vpx_image_t* img, uint32_t timeStamp);
105
106   I420VideoFrame decoded_image_;
107   DecodedImageCallback* decode_complete_callback_;
108   bool inited_;
109   vpx_dec_ctx_t* decoder_;
110   VideoCodec codec_;
111   bool key_frame_required_;
112 };
113 }  // namespace webrtc
114
115 #endif  // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_