Revert 7151 "Revert 7114 "Expose VideoEncoders with webrtc/video_encoder.h.""

Re-lands r7114 after landing r7204 to adress the compile error causing
the rollback in r7151.

BUG=3070
TBR=henrikg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/28489004

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7207 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/common_video/interface/i420_video_frame.h b/common_video/interface/i420_video_frame.h
index 5f7a572..ba23c87 100644
--- a/common_video/interface/i420_video_frame.h
+++ b/common_video/interface/i420_video_frame.h
@@ -11,149 +11,7 @@
 #ifndef COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
 #define COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
 
-// I420VideoFrame class
-//
-// Storing and handling of YUV (I420) video frames.
-
-#include <assert.h>
-
-#include "webrtc/common_video/plane.h"
-#include "webrtc/system_wrappers/interface/scoped_refptr.h"
-#include "webrtc/typedefs.h"
-
-/*
- *  I420VideoFrame includes support for a reference counted impl.
- */
-
-namespace webrtc {
-
-enum PlaneType {
-  kYPlane = 0,
-  kUPlane = 1,
-  kVPlane = 2,
-  kNumOfPlanes = 3
-};
-
-class I420VideoFrame {
- public:
-  I420VideoFrame();
-  virtual ~I420VideoFrame();
-  // Infrastructure for refCount implementation.
-  // Implements dummy functions for reference counting so that non reference
-  // counted instantiation can be done. These functions should not be called
-  // when creating the frame with new I420VideoFrame().
-  // Note: do not pass a I420VideoFrame created with new I420VideoFrame() or
-  // equivalent to a scoped_refptr or memory leak will occur.
-  virtual int32_t AddRef() {assert(false); return -1;}
-  virtual int32_t Release() {assert(false); return -1;}
-
-  // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
-  // on set dimensions - height and plane stride.
-  // If required size is bigger than the allocated one, new buffers of adequate
-  // size will be allocated.
-  // Return value: 0 on success, -1 on error.
-  virtual int CreateEmptyFrame(int width, int height,
-                               int stride_y, int stride_u, int stride_v);
-
-  // CreateFrame: Sets the frame's members and buffers. If required size is
-  // bigger than allocated one, new buffers of adequate size will be allocated.
-  // Return value: 0 on success, -1 on error.
-  virtual int CreateFrame(int size_y, const uint8_t* buffer_y,
-                          int size_u, const uint8_t* buffer_u,
-                          int size_v, const uint8_t* buffer_v,
-                          int width, int height,
-                          int stride_y, int stride_u, int stride_v);
-
-  // Copy frame: If required size is bigger than allocated one, new buffers of
-  // adequate size will be allocated.
-  // Return value: 0 on success, -1 on error.
-  virtual int CopyFrame(const I420VideoFrame& videoFrame);
-
-  // Make a copy of |this|. The caller owns the returned frame.
-  // Return value: a new frame on success, NULL on error.
-  virtual I420VideoFrame* CloneFrame() const;
-
-  // Swap Frame.
-  virtual void SwapFrame(I420VideoFrame* videoFrame);
-
-  // Get pointer to buffer per plane.
-  virtual uint8_t* buffer(PlaneType type);
-  // Overloading with const.
-  virtual const uint8_t* buffer(PlaneType type) const;
-
-  // Get allocated size per plane.
-  virtual int allocated_size(PlaneType type) const;
-
-  // Get allocated stride per plane.
-  virtual int stride(PlaneType type) const;
-
-  // Set frame width.
-  virtual int set_width(int width);
-
-  // Set frame height.
-  virtual int set_height(int height);
-
-  // Get frame width.
-  virtual int width() const {return width_;}
-
-  // Get frame height.
-  virtual int height() const {return height_;}
-
-  // Set frame timestamp (90kHz).
-  virtual void set_timestamp(uint32_t timestamp) {timestamp_ = timestamp;}
-
-  // Get frame timestamp (90kHz).
-  virtual uint32_t timestamp() const {return timestamp_;}
-
-  // Set capture ntp time in miliseconds.
-  virtual void set_ntp_time_ms(int64_t ntp_time_ms) {
-    ntp_time_ms_ = ntp_time_ms;
-  }
-
-  // Get capture ntp time in miliseconds.
-  virtual int64_t ntp_time_ms() const {return ntp_time_ms_;}
-
-  // Set render time in miliseconds.
-  virtual void set_render_time_ms(int64_t render_time_ms) {render_time_ms_ =
-                                                   render_time_ms;}
-
-  // Get render time in miliseconds.
-  virtual int64_t render_time_ms() const {return render_time_ms_;}
-
-  // Return true if underlying plane buffers are of zero size, false if not.
-  virtual bool IsZeroSize() const;
-
-  // Reset underlying plane buffers sizes to 0. This function doesn't
-  // clear memory.
-  virtual void ResetSize();
-
-  // Return the handle of the underlying video frame. This is used when the
-  // frame is backed by a texture. The object should be destroyed when it is no
-  // longer in use, so the underlying resource can be freed.
-  virtual void* native_handle() const;
-
- protected:
-  // Verifies legality of parameters.
-  // Return value: 0 on success, -1 on error.
-  virtual int CheckDimensions(int width, int height,
-                              int stride_y, int stride_u, int stride_v);
-
- private:
-  // Get the pointer to a specific plane.
-  const Plane* GetPlane(PlaneType type) const;
-  // Overloading with non-const.
-  Plane* GetPlane(PlaneType type);
-
-  Plane y_plane_;
-  Plane u_plane_;
-  Plane v_plane_;
-  int width_;
-  int height_;
-  uint32_t timestamp_;
-  int64_t ntp_time_ms_;
-  int64_t render_time_ms_;
-};  // I420VideoFrame
-
-}  // namespace webrtc
+// TODO(pbos): Remove this file and include webrtc/video_frame.h instead.
+#include "webrtc/video_frame.h"
 
 #endif  // COMMON_VIDEO_INTERFACE_I420_VIDEO_FRAME_H
diff --git a/common_video/interface/video_image.h b/common_video/interface/video_image.h
index c8df436..4cbf23f 100644
--- a/common_video/interface/video_image.h
+++ b/common_video/interface/video_image.h
@@ -11,62 +11,7 @@
 #ifndef COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H
 #define COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H
 
-#include <stdlib.h>
-#include "webrtc/typedefs.h"
-
-namespace webrtc
-{
-
-enum VideoFrameType
-{
-    kKeyFrame = 0,
-    kDeltaFrame = 1,
-    kGoldenFrame = 2,
-    kAltRefFrame = 3,
-    kSkipFrame = 4
-};
-
-class EncodedImage
-{
-public:
-    EncodedImage()
-        : _encodedWidth(0),
-          _encodedHeight(0),
-          _timeStamp(0),
-          capture_time_ms_(0),
-          _frameType(kDeltaFrame),
-          _buffer(NULL),
-          _length(0),
-          _size(0),
-          _completeFrame(false) {}
-
-    EncodedImage(uint8_t* buffer,
-                 uint32_t length,
-                 uint32_t size)
-        : _encodedWidth(0),
-          _encodedHeight(0),
-          _timeStamp(0),
-          ntp_time_ms_(0),
-          capture_time_ms_(0),
-          _frameType(kDeltaFrame),
-          _buffer(buffer),
-          _length(length),
-          _size(size),
-          _completeFrame(false) {}
-
-    uint32_t                    _encodedWidth;
-    uint32_t                    _encodedHeight;
-    uint32_t                    _timeStamp;
-    // NTP time of the capture time in local timebase in milliseconds.
-    int64_t ntp_time_ms_;
-    int64_t                      capture_time_ms_;
-    VideoFrameType              _frameType;
-    uint8_t*                    _buffer;
-    uint32_t                    _length;
-    uint32_t                    _size;
-    bool                        _completeFrame;
-};
-
-}  // namespace webrtc
+// TODO(pbos): Remove this file and include webrtc/video_frame.h instead.
+#include "webrtc/video_frame.h"
 
 #endif // COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H
diff --git a/modules/video_coding/codecs/interface/video_codec_interface.h b/modules/video_coding/codecs/interface/video_codec_interface.h
index e6b1d09..82bcd26 100644
--- a/modules/video_coding/codecs/interface/video_codec_interface.h
+++ b/modules/video_coding/codecs/interface/video_codec_interface.h
@@ -15,11 +15,10 @@
 
 #include "webrtc/common_types.h"
 #include "webrtc/common_video/interface/i420_video_frame.h"
-#include "webrtc/common_video/interface/video_image.h"
 #include "webrtc/modules/interface/module_common_types.h"
 #include "webrtc/modules/video_coding/codecs/interface/video_error_codes.h"
-
 #include "webrtc/typedefs.h"
+#include "webrtc/video_encoder.h"
 
 namespace webrtc
 {
@@ -63,106 +62,6 @@
     CodecSpecificInfoUnion codecSpecific;
 };
 
-class EncodedImageCallback
-{
-public:
-    virtual ~EncodedImageCallback() {};
-
-    // Callback function which is called when an image has been encoded.
-    //
-    // Input:
-    //          - encodedImage         : The encoded image
-    //
-    // Return value                    : > 0,   signals to the caller that one or more future frames
-    //                                          should be dropped to keep bit rate or frame rate.
-    //                                   = 0,   if OK.
-    //                                   < 0,   on error.
-    virtual int32_t
-    Encoded(EncodedImage& encodedImage,
-            const CodecSpecificInfo* codecSpecificInfo = NULL,
-            const RTPFragmentationHeader* fragmentation = NULL) = 0;
-};
-
-class VideoEncoder
-{
-public:
-    virtual ~VideoEncoder() {};
-
-    // Initialize the encoder with the information from the VideoCodec.
-    //
-    // Input:
-    //          - codecSettings     : Codec settings
-    //          - numberOfCores     : Number of cores available for the encoder
-    //          - maxPayloadSize    : The maximum size each payload is allowed
-    //                                to have. Usually MTU - overhead.
-    //
-    // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t InitEncode(const VideoCodec* codecSettings, int32_t numberOfCores, uint32_t maxPayloadSize) = 0;
-
-    // Encode an I420 image (as a part of a video stream). The encoded image
-    // will be returned to the user through the encode complete callback.
-    //
-    // Input:
-    //          - inputImage        : Image to be encoded
-    //          - codecSpecificInfo : Pointer to codec specific data
-    //          - frame_types        : The frame type to encode
-    //
-    // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK, < 0
-    //                                otherwise.
-    virtual int32_t Encode(
-        const I420VideoFrame& inputImage,
-        const CodecSpecificInfo* codecSpecificInfo,
-        const std::vector<VideoFrameType>* frame_types) = 0;
-
-    // Register an encode complete callback object.
-    //
-    // Input:
-    //          - callback         : Callback object which handles encoded images.
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t RegisterEncodeCompleteCallback(EncodedImageCallback* callback) = 0;
-
-    // Free encoder memory.
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t Release() = 0;
-
-    // Inform the encoder about the packet loss and round trip time on the
-    // network used to decide the best pattern and signaling.
-    //
-    //          - packetLoss       : Fraction lost (loss rate in percent =
-    //                               100 * packetLoss / 255)
-    //          - rtt              : Round-trip time in milliseconds
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) = 0;
-
-    // Inform the encoder about the new target bit rate.
-    //
-    //          - newBitRate       : New target bit rate
-    //          - frameRate        : The target frame rate
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) = 0;
-
-    // Use this function to enable or disable periodic key frames. Can be useful for codecs
-    // which have other ways of stopping error propagation.
-    //
-    //          - enable           : Enable or disable periodic key frames
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t SetPeriodicKeyFrames(bool enable) { return WEBRTC_VIDEO_CODEC_ERROR; }
-
-    // Codec configuration data to send out-of-band, i.e. in SIP call setup
-    //
-    //          - buffer           : Buffer pointer to where the configuration data
-    //                               should be stored
-    //          - size             : The size of the buffer in bytes
-    //
-    // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
-    virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) { return WEBRTC_VIDEO_CODEC_ERROR; }
-};
-
 class DecodedImageCallback
 {
 public:
diff --git a/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h b/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
index 75fe63f..1e2c9b8 100644
--- a/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
+++ b/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
@@ -16,8 +16,8 @@
 #include <string>
 
 #include "testing/gmock/include/gmock/gmock.h"
-#include "webrtc/common_video/interface/video_image.h"
 #include "webrtc/typedefs.h"
+#include "webrtc/video_frame.h"
 
 namespace webrtc {
 namespace test {
diff --git a/test/configurable_frame_size_encoder.cc b/test/configurable_frame_size_encoder.cc
index b246da3..d3ed784 100644
--- a/test/configurable_frame_size_encoder.cc
+++ b/test/configurable_frame_size_encoder.cc
@@ -12,9 +12,11 @@
 
 #include <string.h>
 
-#include "webrtc/common_video/interface/video_image.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+#include "webrtc/common_video/interface/video_image.h"
+#include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
+
 namespace webrtc {
 namespace test {
 
diff --git a/test/configurable_frame_size_encoder.h b/test/configurable_frame_size_encoder.h
index f29038f..4120bc6 100644
--- a/test/configurable_frame_size_encoder.h
+++ b/test/configurable_frame_size_encoder.h
@@ -14,7 +14,7 @@
 #include <vector>
 
 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
-#include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
+#include "webrtc/video_encoder.h"
 
 namespace webrtc {
 namespace test {
diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc
index ecd3dd8..9551c82 100644
--- a/test/fake_encoder.cc
+++ b/test/fake_encoder.cc
@@ -12,6 +12,8 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 
+#include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
+
 namespace webrtc {
 namespace test {
 
diff --git a/test/fake_encoder.h b/test/fake_encoder.h
index 3c6f735..50b8652 100644
--- a/test/fake_encoder.h
+++ b/test/fake_encoder.h
@@ -13,8 +13,9 @@
 
 #include <vector>
 
-#include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
+#include "webrtc/common_types.h"
 #include "webrtc/system_wrappers/interface/clock.h"
+#include "webrtc/video_encoder.h"
 
 namespace webrtc {
 namespace test {
diff --git a/video/call.cc b/video/call.cc
index 8b71acf..b4adafd 100644
--- a/video/call.cc
+++ b/video/call.cc
@@ -18,6 +18,7 @@
 #include "webrtc/common.h"
 #include "webrtc/config.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
+#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
@@ -41,6 +42,15 @@
          name == webrtc::RtpExtension::kAbsSendTime;
 }
 
+VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) {
+  switch (codec_type) {
+    case kVp8:
+      return VP8Encoder::Create();
+  }
+  assert(false);
+  return NULL;
+}
+
 namespace internal {
 
 class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver {
diff --git a/video/end_to_end_tests.cc b/video/end_to_end_tests.cc
index 114ab65..a83eddc 100644
--- a/video/end_to_end_tests.cc
+++ b/video/end_to_end_tests.cc
@@ -19,7 +19,6 @@
 #include "webrtc/call.h"
 #include "webrtc/frame_callback.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
-#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/interface/event_wrapper.h"
 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
@@ -37,6 +36,7 @@
 #include "webrtc/test/testsupport/fileutils.h"
 #include "webrtc/test/testsupport/perf_test.h"
 #include "webrtc/video/transport_adapter.h"
+#include "webrtc/video_encoder.h"
 
 // Disabled on Android since all tests currently fail (webrtc:3770).
 #ifndef WEBRTC_ANDROID
@@ -645,7 +645,8 @@
   receiver_transport.SetReceiver(sender_call_->Receiver());
 
   CreateSendConfig(1);
-  scoped_ptr<VP8Encoder> encoder(VP8Encoder::Create());
+  scoped_ptr<VideoEncoder> encoder(
+      VideoEncoder::Create(VideoEncoder::kVp8));
   send_config_.encoder_settings.encoder = encoder.get();
   send_config_.encoder_settings.payload_name = "VP8";
   ASSERT_EQ(1u, video_streams_.size()) << "Test setup error.";
@@ -974,9 +975,9 @@
   VideoOutputObserver* observers[kNumStreams];
   test::FrameGeneratorCapturer* frame_generators[kNumStreams];
 
-  scoped_ptr<VP8Encoder> encoders[kNumStreams];
+  scoped_ptr<VideoEncoder> encoders[kNumStreams];
   for (size_t i = 0; i < kNumStreams; ++i)
-    encoders[i].reset(VP8Encoder::Create());
+    encoders[i].reset(VideoEncoder::Create(VideoEncoder::kVp8));
 
   for (size_t i = 0; i < kNumStreams; ++i) {
     uint32_t ssrc = codec_settings[i].ssrc;
diff --git a/video/full_stack.cc b/video/full_stack.cc
index b00eb0e..54abd1f 100644
--- a/video/full_stack.cc
+++ b/video/full_stack.cc
@@ -17,7 +17,6 @@
 #include "webrtc/call.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
-#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
 #include "webrtc/system_wrappers/interface/clock.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/interface/event_wrapper.h"
@@ -391,7 +390,8 @@
 
   CreateSendConfig(1);
 
-  scoped_ptr<VP8Encoder> encoder(VP8Encoder::Create());
+  scoped_ptr<VideoEncoder> encoder(
+      VideoEncoder::Create(VideoEncoder::kVp8));
   send_config_.encoder_settings.encoder = encoder.get();
   send_config_.encoder_settings.payload_name = "VP8";
   send_config_.encoder_settings.payload_type = 124;
diff --git a/video/loopback.cc b/video/loopback.cc
index 4ec7388..29a3c78 100644
--- a/video/loopback.cc
+++ b/video/loopback.cc
@@ -120,7 +120,7 @@
   send_config.local_renderer = local_preview.get();
   scoped_ptr<VideoEncoder> encoder;
   if (flags::Codec() == "VP8") {
-    encoder.reset(VP8Encoder::Create());
+    encoder.reset(VideoEncoder::Create(VideoEncoder::kVp8));
   } else {
     // Codec not supported.
     assert(false && "Codec not supported!");
diff --git a/video_encoder.h b/video_encoder.h
new file mode 100644
index 0000000..6d57d92
--- /dev/null
+++ b/video_encoder.h
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_VIDEO_ENCODER_H_
+#define WEBRTC_VIDEO_ENCODER_H_
+
+#include <vector>
+
+#include "webrtc/typedefs.h"
+#include "webrtc/video_frame.h"
+
+namespace webrtc {
+
+class RTPFragmentationHeader;
+// TODO(pbos): Expose these through a public (root) header or change these APIs.
+struct CodecSpecificInfo;
+struct VideoCodec;
+
+class EncodedImageCallback {
+ public:
+  virtual ~EncodedImageCallback() {}
+
+  // Callback function which is called when an image has been encoded.
+  // TODO(pbos): Make encoded_image const or pointer. Remove default arguments.
+  virtual int32_t Encoded(
+      EncodedImage& encoded_image,
+      const CodecSpecificInfo* codec_specific_info = NULL,
+      const RTPFragmentationHeader* fragmentation = NULL) = 0;
+};
+
+class VideoEncoder {
+ public:
+  enum EncoderType {
+    kVp8,
+  };
+
+  static VideoEncoder* Create(EncoderType codec_type);
+
+  virtual ~VideoEncoder() {}
+
+  virtual int32_t InitEncode(const VideoCodec* codec_settings,
+                             int32_t number_of_cores,
+                             uint32_t max_payload_size) = 0;
+  virtual int32_t RegisterEncodeCompleteCallback(
+      EncodedImageCallback* callback) = 0;
+  virtual int32_t Release() = 0;
+
+
+  virtual int32_t Encode(const I420VideoFrame& frame,
+                         const CodecSpecificInfo* codec_specific_info,
+                         const std::vector<VideoFrameType>* frame_types) = 0;
+
+  virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) = 0;
+  virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0;
+
+  virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
+  virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) {
+    return -1;
+  }
+};
+
+}  // namespace webrtc
+#endif  // WEBRTC_VIDEO_ENCODER_H_
diff --git a/video_frame.h b/video_frame.h
new file mode 100644
index 0000000..f76b9af
--- /dev/null
+++ b/video_frame.h
@@ -0,0 +1,219 @@
+/*
+ *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_VIDEO_FRAME_H_
+#define WEBRTC_VIDEO_FRAME_H_
+
+#include <assert.h>
+
+#include "webrtc/common_video/plane.h"
+// TODO(pbos): Remove scoped_refptr include (and AddRef/Release if they're not
+// used).
+#include "webrtc/system_wrappers/interface/scoped_refptr.h"
+#include "webrtc/typedefs.h"
+
+namespace webrtc {
+
+enum PlaneType {
+  kYPlane = 0,
+  kUPlane = 1,
+  kVPlane = 2,
+  kNumOfPlanes = 3
+};
+
+class I420VideoFrame {
+ public:
+  I420VideoFrame();
+  virtual ~I420VideoFrame();
+  // Infrastructure for refCount implementation.
+  // Implements dummy functions for reference counting so that non reference
+  // counted instantiation can be done. These functions should not be called
+  // when creating the frame with new I420VideoFrame().
+  // Note: do not pass a I420VideoFrame created with new I420VideoFrame() or
+  // equivalent to a scoped_refptr or memory leak will occur.
+  virtual int32_t AddRef() {
+    assert(false);
+    return -1;
+  }
+  virtual int32_t Release() {
+    assert(false);
+    return -1;
+  }
+
+  // CreateEmptyFrame: Sets frame dimensions and allocates buffers based
+  // on set dimensions - height and plane stride.
+  // If required size is bigger than the allocated one, new buffers of adequate
+  // size will be allocated.
+  // Return value: 0 on success, -1 on error.
+  virtual int CreateEmptyFrame(int width,
+                               int height,
+                               int stride_y,
+                               int stride_u,
+                               int stride_v);
+
+  // CreateFrame: Sets the frame's members and buffers. If required size is
+  // bigger than allocated one, new buffers of adequate size will be allocated.
+  // Return value: 0 on success, -1 on error.
+  virtual int CreateFrame(int size_y,
+                          const uint8_t* buffer_y,
+                          int size_u,
+                          const uint8_t* buffer_u,
+                          int size_v,
+                          const uint8_t* buffer_v,
+                          int width,
+                          int height,
+                          int stride_y,
+                          int stride_u,
+                          int stride_v);
+
+  // Copy frame: If required size is bigger than allocated one, new buffers of
+  // adequate size will be allocated.
+  // Return value: 0 on success, -1 on error.
+  virtual int CopyFrame(const I420VideoFrame& videoFrame);
+
+  // Make a copy of |this|. The caller owns the returned frame.
+  // Return value: a new frame on success, NULL on error.
+  virtual I420VideoFrame* CloneFrame() const;
+
+  // Swap Frame.
+  virtual void SwapFrame(I420VideoFrame* videoFrame);
+
+  // Get pointer to buffer per plane.
+  virtual uint8_t* buffer(PlaneType type);
+  // Overloading with const.
+  virtual const uint8_t* buffer(PlaneType type) const;
+
+  // Get allocated size per plane.
+  virtual int allocated_size(PlaneType type) const;
+
+  // Get allocated stride per plane.
+  virtual int stride(PlaneType type) const;
+
+  // Set frame width.
+  virtual int set_width(int width);
+
+  // Set frame height.
+  virtual int set_height(int height);
+
+  // Get frame width.
+  virtual int width() const { return width_; }
+
+  // Get frame height.
+  virtual int height() const { return height_; }
+
+  // Set frame timestamp (90kHz).
+  virtual void set_timestamp(uint32_t timestamp) { timestamp_ = timestamp; }
+
+  // Get frame timestamp (90kHz).
+  virtual uint32_t timestamp() const { return timestamp_; }
+
+  // Set capture ntp time in miliseconds.
+  virtual void set_ntp_time_ms(int64_t ntp_time_ms) {
+    ntp_time_ms_ = ntp_time_ms;
+  }
+
+  // Get capture ntp time in miliseconds.
+  virtual int64_t ntp_time_ms() const { return ntp_time_ms_; }
+
+  // Set render time in miliseconds.
+  virtual void set_render_time_ms(int64_t render_time_ms) {
+    render_time_ms_ = render_time_ms;
+  }
+
+  // Get render time in miliseconds.
+  virtual int64_t render_time_ms() const { return render_time_ms_; }
+
+  // Return true if underlying plane buffers are of zero size, false if not.
+  virtual bool IsZeroSize() const;
+
+  // Reset underlying plane buffers sizes to 0. This function doesn't
+  // clear memory.
+  virtual void ResetSize();
+
+  // Return the handle of the underlying video frame. This is used when the
+  // frame is backed by a texture. The object should be destroyed when it is no
+  // longer in use, so the underlying resource can be freed.
+  virtual void* native_handle() const;
+
+ protected:
+  // Verifies legality of parameters.
+  // Return value: 0 on success, -1 on error.
+  virtual int CheckDimensions(int width,
+                              int height,
+                              int stride_y,
+                              int stride_u,
+                              int stride_v);
+
+ private:
+  // Get the pointer to a specific plane.
+  const Plane* GetPlane(PlaneType type) const;
+  // Overloading with non-const.
+  Plane* GetPlane(PlaneType type);
+
+  Plane y_plane_;
+  Plane u_plane_;
+  Plane v_plane_;
+  int width_;
+  int height_;
+  uint32_t timestamp_;
+  int64_t ntp_time_ms_;
+  int64_t render_time_ms_;
+};
+
+enum VideoFrameType {
+  kKeyFrame = 0,
+  kDeltaFrame = 1,
+  kGoldenFrame = 2,
+  kAltRefFrame = 3,
+  kSkipFrame = 4
+};
+
+// TODO(pbos): Rename EncodedFrame and reformat this class' members.
+class EncodedImage {
+ public:
+  EncodedImage()
+      : _encodedWidth(0),
+        _encodedHeight(0),
+        _timeStamp(0),
+        capture_time_ms_(0),
+        _frameType(kDeltaFrame),
+        _buffer(NULL),
+        _length(0),
+        _size(0),
+        _completeFrame(false) {}
+
+  EncodedImage(uint8_t* buffer, uint32_t length, uint32_t size)
+      : _encodedWidth(0),
+        _encodedHeight(0),
+        _timeStamp(0),
+        ntp_time_ms_(0),
+        capture_time_ms_(0),
+        _frameType(kDeltaFrame),
+        _buffer(buffer),
+        _length(length),
+        _size(size),
+        _completeFrame(false) {}
+
+  uint32_t _encodedWidth;
+  uint32_t _encodedHeight;
+  uint32_t _timeStamp;
+  // NTP time of the capture time in local timebase in milliseconds.
+  int64_t ntp_time_ms_;
+  int64_t capture_time_ms_;
+  VideoFrameType _frameType;
+  uint8_t* _buffer;
+  uint32_t _length;
+  uint32_t _size;
+  bool _completeFrame;
+};
+
+}  // namespace webrtc
+#endif  // WEBRTC_VIDEO_FRAME_H_
+