AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CodedData.cpp
Go to the documentation of this file.
1 #include "CodedData.hpp"
2 
3 #include <cstring>
4 
5 namespace avtranscoder
6 {
7 
9  : _avStream(NULL)
10 {
11  initAVPacket();
12 }
13 
14 CodedData::CodedData(const size_t dataSize)
15  : _avStream(NULL)
16 {
17  av_new_packet(&_packet, dataSize);
18 }
19 
20 CodedData::CodedData(const AVPacket& avPacket)
21  : _avStream(NULL)
22 {
23  copyAVPacket(avPacket);
24 }
25 
27 {
28  copyAVPacket(other.getAVPacket());
29  _avStream = other.getAVStream();
30 }
31 
33 {
34  copyAVPacket(other.getAVPacket());
35  _avStream = other.getAVStream();
36  return *this;
37 }
38 
40 {
41  av_free_packet(&_packet);
42 }
43 
44 void CodedData::resize(const size_t newSize)
45 {
46  if((int)newSize < _packet.size)
47  av_shrink_packet(&_packet, newSize);
48  else if((int)newSize > _packet.size)
49  av_grow_packet(&_packet, newSize - _packet.size);
50 }
51 
52 void CodedData::refData(unsigned char* buffer, const size_t size)
53 {
54  _packet.data = buffer;
55  _packet.size = size;
56 }
57 
58 void CodedData::copyData(unsigned char* buffer, const size_t size)
59 {
60  resize(size);
61  if(size != 0)
62  memcpy(_packet.data, buffer, _packet.size);
63 }
64 
66 {
67  _packet.data = frame.getData();
68  _packet.size = frame.getSize();
69 }
70 
72 {
73  av_free_packet(&_packet);
74  initAVPacket();
75 }
76 
77 void CodedData::assign(const size_t size, const int value)
78 {
79  resize(size);
80  memset(_packet.data, value, size);
81 }
82 
84 {
85  av_init_packet(&_packet);
86  _packet.data = NULL;
87  _packet.size = 0;
88 }
89 
90 void CodedData::copyAVPacket(const AVPacket& avPacket)
91 {
92 #if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
93  // Need const_cast<AVCodec*> for libav versions from 54.56. to 55.56.
94  av_copy_packet(&_packet, const_cast<AVPacket*>(&avPacket));
95 #else
96  // @todo: we just care about data, not side properties of AVPacket
97  initAVPacket();
98  copyData(avPacket.data, avPacket.size);
99 #endif
100 }
101 }
void refData(CodedData &frame)
Definition: CodedData.cpp:65
CodedData()
Create an empty data buffer.
Definition: CodedData.cpp:8
void copyAVPacket(const AVPacket &avPacket)
Definition: CodedData.cpp:90
unsigned char * getData()
Definition: CodedData.hpp:65
void clear()
Clear existing data and set size to 0.
Definition: CodedData.cpp:71
void copyData(unsigned char *buffer, const size_t size)
Copy external data buffer.
Definition: CodedData.cpp:58
const AVStream * getAVStream() const
Definition: CodedData.hpp:77
AVPacket & getAVPacket()
Definition: CodedData.hpp:78
CodedData & operator=(const CodedData &other)
Override operator = in order to copy AVPacket data.
Definition: CodedData.cpp:32
~CodedData()
Free buffer of data.
Definition: CodedData.cpp:39
void assign(const size_t size, const int value)
Resize the buffer with the given size, and copy the given value.
Definition: CodedData.cpp:77
const AVStream * _avStream
Definition: CodedData.hpp:90
size_t getSize() const
Definition: CodedData.hpp:70
void resize(const size_t newSize)
Resize data buffer.
Definition: CodedData.cpp:44
This class describes coded data.
Definition: CodedData.hpp:18