avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
packet.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <vector>
5 
6 #include "ffmpeg.h"
7 #include "rational.h"
8 #include "stream.h"
9 #include "averror.h"
10 #include "timestamp.h"
11 
12 extern "C" {
13 #include <libavutil/attributes.h>
14 }
15 
16 namespace av {
17 
18 class Packet :
19 #if DEPRECATED_INIT_PACKET
20  public FFWrapperPtr<AVPacket>
21 #else
22  public FFWrapperRef<AVPacket>
23 #endif
24 {
25 private:
26  // if deepCopy true - make deep copy, instead - reference is created
27  void initFromAVPacket(const AVPacket *avpacket, bool deepCopy, OptionalErrorCode ec);
28 
29 public:
33  struct wrap_data {};
38  struct wrap_data_static {};
39 
40  Packet();
41  Packet(const Packet &packet, OptionalErrorCode ec);
42  Packet(const Packet &packet);
43  Packet(Packet &&packet);
44  explicit Packet(const AVPacket *packet, OptionalErrorCode ec = throws());
45  explicit Packet(const std::vector<uint8_t> &data);
46  Packet(const uint8_t *data, size_t size, bool doAllign = true);
47  // data must be allocated with av_malloc() family
48  Packet(uint8_t *data, size_t size, wrap_data, OptionalErrorCode ec = throws());
49  Packet(uint8_t *data, size_t size, wrap_data_static, OptionalErrorCode ec = throws());
50  ~Packet();
51 
52  bool setData(const std::vector<uint8_t> &newData, OptionalErrorCode ec = throws());
53  bool setData(const uint8_t *newData, size_t size, OptionalErrorCode ec = throws());
54 
55  const uint8_t* data() const;
56  uint8_t* data();
57 
58  Timestamp pts() const;
59  Timestamp dts() const;
60  Timestamp ts() const;
61  size_t size() const;
62 
70  attribute_deprecated void setPts(int64_t pts, const Rational &tsTimeBase = Rational(0, 0));
71  attribute_deprecated void setDts(int64_t dts, const Rational &tsTimeBase = Rational(0, 0));
72 
73  void setPts(const Timestamp &pts);
74  void setDts(const Timestamp &dts);
75 
76  int streamIndex() const;
77  bool isKeyPacket() const;
78  int duration() const;
79  bool isComplete() const;
80  bool isNull() const;
81 
82  void setStreamIndex(int idx);
83  void setKeyPacket(bool keyPacket);
84  void setDuration(int duration, const Rational &durationTimeBase = Rational(0, 0));
85  void setComplete(bool complete);
86 
87  // Flags
88  int flags() const;
89  void setFlags(int flags);
90  void addFlags(int flags);
91  void clearFlags(int flags);
92 
93  void dump(const Stream & st, bool dumpPayload = false) const;
94 
95  const Rational& timeBase() const { return m_timeBase; }
96  void setTimeBase(const Rational &value);
97 
98  bool isReferenced() const;
99  int refCount() const;
100 
101 #if DEPRECATED_INIT_PACKET
102  AVPacket* makeRef(OptionalErrorCode ec) const;
103 #else
104  AVPacket makeRef(OptionalErrorCode ec = throws()) const;
105 #endif
106 
107  Packet clone(OptionalErrorCode ec = throws()) const;
108 
109  Packet &operator=(const Packet &rhs);
110  Packet &operator=(Packet &&rhs);
111 
112 #if DEPRECATED_INIT_PACKET
113  Packet &operator=(const AVPacket *rhs);
114 #else
115  Packet &operator=(const AVPacket &rhs);
116 #endif
117 
118  void swap(Packet &other);
119 
120  operator bool() const { return isComplete(); }
121 
122 private:
123 #if 0
124  int allocatePayload(int32_t size);
125  int reallocatePayload(int32_t newSize);
126 #endif
127 
128 private:
129  bool m_completeFlag;
130  Rational m_timeBase;
131 };
132 
133 
134 
135 } // ::av
136 
av::Packet::ts
Timestamp ts() const
Definition: packet.cpp:219
av::Packet::setData
bool setData(const std::vector< uint8_t > &newData, OptionalErrorCode ec=throws())
av::Rational
Definition: rational.h:24
rational.h
av::Packet::addFlags
void addFlags(int flags)
Definition: packet.cpp:307
av::Packet::isKeyPacket
bool isKeyPacket() const
Definition: packet.cpp:269
av::Packet::streamIndex
int streamIndex() const
Definition: packet.cpp:259
averror.h
av::Packet::setTimeBase
void setTimeBase(const Rational &value)
Definition: packet.cpp:326
ffmpeg.h
FFWrapperPtr
Definition: ffmpeg.h:68
av::Packet::setStreamIndex
void setStreamIndex(int idx)
Definition: packet.cpp:289
av::Packet::setDts
attribute_deprecated void setDts(int64_t dts, const Rational &tsTimeBase=Rational(0, 0))
Definition: packet.cpp:237
av::Packet::makeRef
AVPacket makeRef(OptionalErrorCode ec=throws()) const
Definition: packet.cpp:374
av::OptionalErrorCode
Definition: averror.h:63
av::Packet::clone
Packet clone(OptionalErrorCode ec=throws()) const
Definition: packet.cpp:386
av::Packet::timeBase
const Rational & timeBase() const
Definition: packet.h:95
av::Packet::wrap_data_static
Wrap static data, do not owning and free.
Definition: packet.h:38
av::Packet::size
size_t size() const
Definition: packet.cpp:224
av::Packet::dump
void dump(const Stream &st, bool dumpPayload=false) const
Definition: packet.cpp:317
av::Packet::setPts
attribute_deprecated void setPts(int64_t pts, const Rational &tsTimeBase=Rational(0, 0))
Set packet PTS field.
Definition: packet.cpp:229
av::Packet::flags
int flags() const
Definition: packet.cpp:264
stream.h
av::Packet::data
const uint8_t * data() const
Definition: packet.cpp:199
av::Packet::isComplete
bool isComplete() const
Definition: packet.cpp:279
av::Packet::pts
Timestamp pts() const
Definition: packet.cpp:209
FFWrapperRef
Definition: ffmpeg.h:108
av::Packet::clearFlags
void clearFlags(int flags)
Definition: packet.cpp:312
av::Packet::dts
Timestamp dts() const
Definition: packet.cpp:214
av::Packet::setFlags
void setFlags(int flags)
Definition: packet.cpp:302
av::Packet::wrap_data
Wrap data and take owning.
Definition: packet.h:33
av::Packet::duration
int duration() const
Definition: packet.cpp:274
av::Packet
Definition: packet.h:18
av::Packet::setDuration
void setDuration(int duration, const Rational &durationTimeBase=Rational(0, 0))
Definition: packet.cpp:449
av
Definition: audioresampler.cpp:8
av::Packet::Packet
Packet()
Definition: packet.cpp:8
av::Packet::swap
void swap(Packet &other)
Definition: packet.cpp:441
av::Packet::refCount
int refCount() const
Definition: packet.cpp:344
av::Packet::setComplete
void setComplete(bool complete)
Definition: packet.cpp:394
av::Timestamp
The Timestamp class represents timestamp value and it timebase.
Definition: timestamp.h:13
av::Packet::setKeyPacket
void setKeyPacket(bool keyPacket)
Definition: packet.cpp:294
av::Packet::isReferenced
bool isReferenced() const
Definition: packet.cpp:339
av::Packet::isNull
bool isNull() const
Definition: packet.cpp:284
av::Packet::~Packet
~Packet()
Definition: packet.cpp:101
av::Packet::operator=
Packet & operator=(const Packet &rhs)
Definition: packet.cpp:399
timestamp.h
av::Stream
Definition: stream.h:22