LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/video_coding - encoded_frame.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 143 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 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/include/video_coding_defines.h"
      12             : #include "webrtc/modules/video_coding/encoded_frame.h"
      13             : #include "webrtc/modules/video_coding/generic_encoder.h"
      14             : #include "webrtc/modules/video_coding/jitter_buffer_common.h"
      15             : 
      16             : namespace webrtc {
      17             : 
      18           0 : VCMEncodedFrame::VCMEncodedFrame()
      19             :     : webrtc::EncodedImage(),
      20             :       _renderTimeMs(-1),
      21             :       _payloadType(0),
      22             :       _missingFrame(false),
      23             :       _codec(kVideoCodecUnknown),
      24           0 :       _rotation_set(false) {
      25           0 :   _codecSpecificInfo.codecType = kVideoCodecUnknown;
      26           0 : }
      27             : 
      28           0 : VCMEncodedFrame::VCMEncodedFrame(const webrtc::EncodedImage& rhs)
      29             :     : webrtc::EncodedImage(rhs),
      30             :       _renderTimeMs(-1),
      31             :       _payloadType(0),
      32             :       _missingFrame(false),
      33             :       _codec(kVideoCodecUnknown),
      34           0 :       _rotation_set(false) {
      35           0 :   _codecSpecificInfo.codecType = kVideoCodecUnknown;
      36           0 :   _buffer = NULL;
      37           0 :   _size = 0;
      38           0 :   _length = 0;
      39           0 :   if (rhs._buffer != NULL) {
      40           0 :     VerifyAndAllocate(rhs._length +
      41           0 :                       EncodedImage::GetBufferPaddingBytes(_codec));
      42           0 :     memcpy(_buffer, rhs._buffer, rhs._length);
      43             :   }
      44           0 : }
      45             : 
      46           0 : VCMEncodedFrame::VCMEncodedFrame(const VCMEncodedFrame& rhs)
      47             :     : webrtc::EncodedImage(rhs),
      48           0 :       _renderTimeMs(rhs._renderTimeMs),
      49           0 :       _payloadType(rhs._payloadType),
      50           0 :       _missingFrame(rhs._missingFrame),
      51             :       _codecSpecificInfo(rhs._codecSpecificInfo),
      52           0 :       _codec(rhs._codec),
      53           0 :       _rotation_set(rhs._rotation_set) {
      54           0 :   _buffer = NULL;
      55           0 :   _size = 0;
      56           0 :   _length = 0;
      57           0 :   if (rhs._buffer != NULL) {
      58           0 :     VerifyAndAllocate(rhs._length +
      59           0 :                       EncodedImage::GetBufferPaddingBytes(_codec));
      60           0 :     memcpy(_buffer, rhs._buffer, rhs._length);
      61           0 :     _length = rhs._length;
      62             :   }
      63           0 : }
      64             : 
      65           0 : VCMEncodedFrame::~VCMEncodedFrame() {
      66           0 :   Free();
      67           0 : }
      68             : 
      69           0 : void VCMEncodedFrame::Free() {
      70           0 :   Reset();
      71           0 :   if (_buffer != NULL) {
      72           0 :     delete[] _buffer;
      73           0 :     _buffer = NULL;
      74             :   }
      75           0 : }
      76             : 
      77           0 : void VCMEncodedFrame::Reset() {
      78           0 :   _renderTimeMs = -1;
      79           0 :   _timeStamp = 0;
      80           0 :   _payloadType = 0;
      81           0 :   _frameType = kVideoFrameDelta;
      82           0 :   _encodedWidth = 0;
      83           0 :   _encodedHeight = 0;
      84           0 :   _completeFrame = false;
      85           0 :   _missingFrame = false;
      86           0 :   _length = 0;
      87           0 :   _codecSpecificInfo.codecType = kVideoCodecUnknown;
      88           0 :   _codec = kVideoCodecUnknown;
      89           0 :   rotation_ = kVideoRotation_0;
      90           0 :   _rotation_set = false;
      91           0 : }
      92             : 
      93           0 : void VCMEncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) {
      94           0 :   if (header) {
      95           0 :     switch (header->codec) {
      96             :       case kRtpVideoVp8: {
      97           0 :         if (_codecSpecificInfo.codecType != kVideoCodecVP8) {
      98             :           // This is the first packet for this frame.
      99           0 :           _codecSpecificInfo.codecSpecific.VP8.pictureId = -1;
     100           0 :           _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0;
     101           0 :           _codecSpecificInfo.codecSpecific.VP8.layerSync = false;
     102           0 :           _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1;
     103           0 :           _codecSpecificInfo.codecType = kVideoCodecVP8;
     104             :         }
     105           0 :         _codecSpecificInfo.codecSpecific.VP8.nonReference =
     106           0 :             header->codecHeader.VP8.nonReference;
     107           0 :         if (header->codecHeader.VP8.pictureId != kNoPictureId) {
     108           0 :           _codecSpecificInfo.codecSpecific.VP8.pictureId =
     109           0 :               header->codecHeader.VP8.pictureId;
     110             :         }
     111           0 :         if (header->codecHeader.VP8.temporalIdx != kNoTemporalIdx) {
     112           0 :           _codecSpecificInfo.codecSpecific.VP8.temporalIdx =
     113           0 :               header->codecHeader.VP8.temporalIdx;
     114           0 :           _codecSpecificInfo.codecSpecific.VP8.layerSync =
     115           0 :               header->codecHeader.VP8.layerSync;
     116             :         }
     117           0 :         if (header->codecHeader.VP8.keyIdx != kNoKeyIdx) {
     118           0 :           _codecSpecificInfo.codecSpecific.VP8.keyIdx =
     119           0 :               header->codecHeader.VP8.keyIdx;
     120             :         }
     121           0 :         break;
     122             :       }
     123             :       case kRtpVideoVp9: {
     124           0 :         if (_codecSpecificInfo.codecType != kVideoCodecVP9) {
     125             :           // This is the first packet for this frame.
     126           0 :           _codecSpecificInfo.codecSpecific.VP9.picture_id = -1;
     127           0 :           _codecSpecificInfo.codecSpecific.VP9.temporal_idx = 0;
     128           0 :           _codecSpecificInfo.codecSpecific.VP9.spatial_idx = 0;
     129           0 :           _codecSpecificInfo.codecSpecific.VP9.gof_idx = 0;
     130           0 :           _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = false;
     131           0 :           _codecSpecificInfo.codecSpecific.VP9.tl0_pic_idx = -1;
     132           0 :           _codecSpecificInfo.codecType = kVideoCodecVP9;
     133             :         }
     134           0 :         _codecSpecificInfo.codecSpecific.VP9.inter_pic_predicted =
     135           0 :             header->codecHeader.VP9.inter_pic_predicted;
     136           0 :         _codecSpecificInfo.codecSpecific.VP9.flexible_mode =
     137           0 :             header->codecHeader.VP9.flexible_mode;
     138           0 :         _codecSpecificInfo.codecSpecific.VP9.num_ref_pics =
     139           0 :             header->codecHeader.VP9.num_ref_pics;
     140           0 :         for (uint8_t r = 0; r < header->codecHeader.VP9.num_ref_pics; ++r) {
     141           0 :           _codecSpecificInfo.codecSpecific.VP9.p_diff[r] =
     142           0 :               header->codecHeader.VP9.pid_diff[r];
     143             :         }
     144           0 :         _codecSpecificInfo.codecSpecific.VP9.ss_data_available =
     145           0 :             header->codecHeader.VP9.ss_data_available;
     146           0 :         if (header->codecHeader.VP9.picture_id != kNoPictureId) {
     147           0 :           _codecSpecificInfo.codecSpecific.VP9.picture_id =
     148           0 :               header->codecHeader.VP9.picture_id;
     149             :         }
     150           0 :         if (header->codecHeader.VP9.tl0_pic_idx != kNoTl0PicIdx) {
     151           0 :           _codecSpecificInfo.codecSpecific.VP9.tl0_pic_idx =
     152           0 :               header->codecHeader.VP9.tl0_pic_idx;
     153             :         }
     154           0 :         if (header->codecHeader.VP9.temporal_idx != kNoTemporalIdx) {
     155           0 :           _codecSpecificInfo.codecSpecific.VP9.temporal_idx =
     156           0 :               header->codecHeader.VP9.temporal_idx;
     157           0 :           _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch =
     158           0 :               header->codecHeader.VP9.temporal_up_switch;
     159             :         }
     160           0 :         if (header->codecHeader.VP9.spatial_idx != kNoSpatialIdx) {
     161           0 :           _codecSpecificInfo.codecSpecific.VP9.spatial_idx =
     162           0 :               header->codecHeader.VP9.spatial_idx;
     163           0 :           _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted =
     164           0 :               header->codecHeader.VP9.inter_layer_predicted;
     165             :         }
     166           0 :         if (header->codecHeader.VP9.gof_idx != kNoGofIdx) {
     167           0 :           _codecSpecificInfo.codecSpecific.VP9.gof_idx =
     168           0 :               header->codecHeader.VP9.gof_idx;
     169             :         }
     170           0 :         if (header->codecHeader.VP9.ss_data_available) {
     171           0 :           _codecSpecificInfo.codecSpecific.VP9.num_spatial_layers =
     172           0 :               header->codecHeader.VP9.num_spatial_layers;
     173             :           _codecSpecificInfo.codecSpecific.VP9
     174           0 :               .spatial_layer_resolution_present =
     175           0 :               header->codecHeader.VP9.spatial_layer_resolution_present;
     176           0 :           if (header->codecHeader.VP9.spatial_layer_resolution_present) {
     177           0 :             for (size_t i = 0; i < header->codecHeader.VP9.num_spatial_layers;
     178             :                  ++i) {
     179           0 :               _codecSpecificInfo.codecSpecific.VP9.width[i] =
     180           0 :                   header->codecHeader.VP9.width[i];
     181           0 :               _codecSpecificInfo.codecSpecific.VP9.height[i] =
     182           0 :                   header->codecHeader.VP9.height[i];
     183             :             }
     184             :           }
     185           0 :           _codecSpecificInfo.codecSpecific.VP9.gof.CopyGofInfoVP9(
     186           0 :               header->codecHeader.VP9.gof);
     187             :         }
     188           0 :         break;
     189             :       }
     190             :       case kRtpVideoH264: {
     191           0 :         _codecSpecificInfo.codecType = kVideoCodecH264;
     192           0 :         break;
     193             :       }
     194             :       default: {
     195           0 :         _codecSpecificInfo.codecType = kVideoCodecUnknown;
     196           0 :         break;
     197             :       }
     198             :     }
     199             :   }
     200           0 : }
     201             : 
     202           0 : void VCMEncodedFrame::VerifyAndAllocate(size_t minimumSize) {
     203           0 :   if (minimumSize > _size) {
     204             :     // create buffer of sufficient size
     205           0 :     uint8_t* newBuffer = new uint8_t[minimumSize];
     206           0 :     if (_buffer) {
     207             :       // copy old data
     208           0 :       memcpy(newBuffer, _buffer, _size);
     209           0 :       delete[] _buffer;
     210             :     }
     211           0 :     _buffer = newBuffer;
     212           0 :     _size = minimumSize;
     213             :   }
     214           0 : }
     215             : 
     216             : }  // namespace webrtc

Generated by: LCOV version 1.13