1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/*
2470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *
4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  Use of this source code is governed by a BSD-style license
5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  that can be found in the LICENSE file in the root of the source
6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  tree. An additional intellectual property rights grant can be found
7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  in the file PATENTS.  All contributing project authors may
8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  be found in the AUTHORS file in the root of the source tree.
9470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */
10470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
11470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#ifndef WEBRTC_MODULES_VIDEO_CODING_ENCODED_FRAME_H_
12470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#define WEBRTC_MODULES_VIDEO_CODING_ENCODED_FRAME_H_
13470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
14c5300436841092d6d2b01eae1179a2c1eb373f1bstefan@webrtc.org#include <vector>
15c5300436841092d6d2b01eae1179a2c1eb373f1bstefan@webrtc.org
16a4407329d4e16eab3d2e87cde0824188c06acb5apbos@webrtc.org#include "webrtc/common_types.h"
176f8ce060a21fcdc1c951fbf06768eb0cc0083b2fkjellander#include "webrtc/common_video/include/video_image.h"
18ff761fba8274d93bd73e76c8b8a1f2d0776dd840Henrik Kjellander#include "webrtc/modules/include/module_common_types.h"
192557b86e7648ffebc5781df9f093ca5a84efc219Henrik Kjellander#include "webrtc/modules/video_coding/include/video_codec_interface.h"
202557b86e7648ffebc5781df9f093ca5a84efc219Henrik Kjellander#include "webrtc/modules/video_coding/include/video_coding_defines.h"
21470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
229d3ab61325c5ed216ea52bc829f1d8c81347459bphilipelnamespace webrtc {
23470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
249d3ab61325c5ed216ea52bc829f1d8c81347459bphilipelclass VCMEncodedFrame : protected EncodedImage {
259d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel public:
269d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  VCMEncodedFrame();
279d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  explicit VCMEncodedFrame(const webrtc::EncodedImage& rhs);
289d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  VCMEncodedFrame(const VCMEncodedFrame& rhs);
29470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
309d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  ~VCMEncodedFrame();
319d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
329d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Delete VideoFrame and resets members to zero
339d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
349d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void Free();
359d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
369d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Set render time in milliseconds
379d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
389d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void SetRenderTime(const int64_t renderTimeMs) {
399d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel    _renderTimeMs = renderTimeMs;
409d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  }
41470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
429d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
439d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Set the encoded frame size
449d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
459d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void SetEncodedSize(uint32_t width, uint32_t height) {
469d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel    _encodedWidth = width;
479d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel    _encodedHeight = height;
489d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  }
499d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
509d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get the encoded image
519d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
529d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  const webrtc::EncodedImage& EncodedImage() const {
539d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel    return static_cast<const webrtc::EncodedImage&>(*this);
549d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  }
559d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
569d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get pointer to frame buffer
579d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
589d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  const uint8_t* Buffer() const { return _buffer; }
599d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
609d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get frame length
619d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
629d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  size_t Length() const { return _length; }
639d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
649d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get frame timestamp (90kHz)
659d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
669d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  uint32_t TimeStamp() const { return _timeStamp; }
679d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
689d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get render time in milliseconds
699d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
709d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  int64_t RenderTimeMs() const { return _renderTimeMs; }
719d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
729d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get frame type
739d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
749d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  webrtc::FrameType FrameType() const { return _frameType; }
759d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
769d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get frame rotation
779d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
789d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  VideoRotation rotation() const { return _rotation; }
799d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
809d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   True if this frame is complete, false otherwise
819d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
829d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  bool Complete() const { return _completeFrame; }
839d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
849d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   True if there's a frame missing before this frame
859d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
869d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  bool MissingFrame() const { return _missingFrame; }
879d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
889d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Payload type of the encoded payload
899d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
909d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  uint8_t PayloadType() const { return _payloadType; }
919d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
929d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   Get codec specific info.
939d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   The returned pointer is only valid as long as the VCMEncodedFrame
949d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   is valid. Also, VCMEncodedFrame owns the pointer and will delete
959d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  *   the object.
969d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
979d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  const CodecSpecificInfo* CodecSpecific() const { return &_codecSpecificInfo; }
98470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
999d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  const RTPFragmentationHeader* FragmentationHeader() const;
100c3d891059e117357011e414263af0f519313d440stefan@webrtc.org
1019d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel protected:
1029d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  /**
1039d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * Verifies that current allocated buffer size is larger than or equal to the
1049d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * input size.
1059d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * If the current buffer size is smaller, a new allocation is made and the old
1069d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * buffer data
1079d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * is copied to the new buffer.
1089d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  * Buffer size is updated to minimumSize.
1099d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  */
1109d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void VerifyAndAllocate(size_t minimumSize);
111470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
1129d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void Reset();
113470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
1149d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  void CopyCodecSpecific(const RTPVideoHeader* header);
115473bac8582896a9ddfafe8ca740578e56946bb7bhenrik.lundin@webrtc.org
1169d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  int64_t _renderTimeMs;
1179d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  uint8_t _payloadType;
1189d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  bool _missingFrame;
1199d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  CodecSpecificInfo _codecSpecificInfo;
1209d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  webrtc::VideoCodecType _codec;
1219d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  RTPFragmentationHeader _fragmentation;
1229d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  VideoRotation _rotation;
12354d072ea20594165c8f124ef382a3de0d111f938guoweis@webrtc.org
1249d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  // Video rotation is only set along with the last packet for each frame
1259d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  // (same as marker bit). This |_rotation_set| is only for debugging purpose
1269d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  // to ensure we don't set it twice for a frame.
1279d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel  bool _rotation_set;
128470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com};
129470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
130d900e8bea84c474696bf0219aed1353ce65ffd8epbos@webrtc.org}  // namespace webrtc
131470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
1329d3ab61325c5ed216ea52bc829f1d8c81347459bphilipel#endif  // WEBRTC_MODULES_VIDEO_CODING_ENCODED_FRAME_H_
133