blob: c33fdf749b81b908fab9c29497c4d61308692c44 [file] [log] [blame]
philipelc707ab72016-04-01 02:01:54 -07001/*
2 * Copyright (c) 2016 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#include "webrtc/modules/video_coding/frame_object.h"
12#include "webrtc/base/criticalsection.h"
13#include "webrtc/modules/video_coding/packet_buffer.h"
14
15namespace webrtc {
16namespace video_coding {
17
philipela1059872016-05-09 11:41:48 +020018FrameObject::FrameObject()
19 : picture_id(0),
20 spatial_layer(0),
philipelbe7a9e52016-05-19 12:19:35 +020021 timestamp(0),
philipela1059872016-05-09 11:41:48 +020022 num_references(0),
23 inter_layer_predicted(false) {}
24
philipelc707ab72016-04-01 02:01:54 -070025RtpFrameObject::RtpFrameObject(PacketBuffer* packet_buffer,
philipel02447bc2016-05-13 06:01:03 -070026 uint16_t first_seq_num,
philipel5ceaaae2016-05-24 10:20:47 +020027 uint16_t last_seq_num,
28 size_t frame_size,
29 int times_nacked)
philipelc707ab72016-04-01 02:01:54 -070030 : packet_buffer_(packet_buffer),
philipel02447bc2016-05-13 06:01:03 -070031 first_seq_num_(first_seq_num),
philipel5ceaaae2016-05-24 10:20:47 +020032 last_seq_num_(last_seq_num),
33 times_nacked_(times_nacked) {
34 size = frame_size;
philipel02447bc2016-05-13 06:01:03 -070035 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num);
36 if (packet) {
philipel552866c2016-07-04 16:18:55 +020037 // TODO(philipel): Remove when encoded image is replaced by FrameObject.
38 // VCMEncodedFrame members
39 CopyCodecSpecific(&packet->video_header);
40 _completeFrame = true;
41 _payloadType = packet->payloadType;
42 _timeStamp = packet->timestamp;
43 ntp_time_ms_ = packet->ntp_time_ms_;
44 _buffer = new uint8_t[frame_size]();
45 _size = frame_size;
46 _length = frame_size;
47 _frameType = packet->frameType;
48 GetBitstream(_buffer);
49
50 // RtpFrameObject members
philipel02447bc2016-05-13 06:01:03 -070051 frame_type_ = packet->frameType;
52 codec_type_ = packet->codec;
philipel552866c2016-07-04 16:18:55 +020053
54 // FrameObject members
55 timestamp = packet->timestamp;
philipel02447bc2016-05-13 06:01:03 -070056 }
57}
philipelc707ab72016-04-01 02:01:54 -070058
59RtpFrameObject::~RtpFrameObject() {
60 packet_buffer_->ReturnFrame(this);
61}
62
philipelf4139332016-04-20 10:26:34 +020063uint16_t RtpFrameObject::first_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070064 return first_seq_num_;
philipelc707ab72016-04-01 02:01:54 -070065}
66
philipelf4139332016-04-20 10:26:34 +020067uint16_t RtpFrameObject::last_seq_num() const {
philipel02447bc2016-05-13 06:01:03 -070068 return last_seq_num_;
69}
70
philipel5ceaaae2016-05-24 10:20:47 +020071int RtpFrameObject::times_nacked() const {
72 return times_nacked_;
73}
74
philipel02447bc2016-05-13 06:01:03 -070075FrameType RtpFrameObject::frame_type() const {
76 return frame_type_;
77}
78
79VideoCodecType RtpFrameObject::codec_type() const {
80 return codec_type_;
philipelc707ab72016-04-01 02:01:54 -070081}
82
philipelc707ab72016-04-01 02:01:54 -070083bool RtpFrameObject::GetBitstream(uint8_t* destination) const {
84 return packet_buffer_->GetBitstream(*this, destination);
85}
86
philipel02447bc2016-05-13 06:01:03 -070087RTPVideoTypeHeader* RtpFrameObject::GetCodecHeader() const {
88 VCMPacket* packet = packet_buffer_->GetPacket(first_seq_num_);
89 if (!packet)
90 return nullptr;
isheriff6b4b5f32016-06-08 00:24:21 -070091 return &packet->video_header.codecHeader;
philipel02447bc2016-05-13 06:01:03 -070092}
93
philipelc707ab72016-04-01 02:01:54 -070094} // namespace video_coding
95} // namespace webrtc