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 <vector>
4 
5 #include "ffmpeg.h"
6 #include "avutils.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 API_AVCODEC_NEW_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 API_AVCODEC_NEW_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 API_AVCODEC_NEW_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 
Definition: averror.h:64
Definition: packet.h:24
Timestamp ts() const
Definition: packet.cpp:218
Timestamp pts() const
Definition: packet.cpp:208
const uint8_t * data() const
Definition: packet.cpp:198
~Packet()
Definition: packet.cpp:100
int flags() const
Definition: packet.cpp:263
void setKeyPacket(bool keyPacket)
Definition: packet.cpp:293
bool isComplete() const
Definition: packet.cpp:278
Timestamp dts() const
Definition: packet.cpp:213
void setComplete(bool complete)
Definition: packet.cpp:393
Packet & operator=(const Packet &rhs)
Definition: packet.cpp:398
void dump(const Stream &st, bool dumpPayload=false) const
Definition: packet.cpp:316
bool isNull() const
Definition: packet.cpp:283
size_t size() const
Definition: packet.cpp:223
int streamIndex() const
Definition: packet.cpp:258
attribute_deprecated void setDts(int64_t dts, const Rational &tsTimeBase=Rational(0, 0))
Definition: packet.cpp:236
Packet clone(OptionalErrorCode ec=throws()) const
Definition: packet.cpp:385
int refCount() const
Definition: packet.cpp:343
const Rational & timeBase() const
Definition: packet.h:95
attribute_deprecated void setPts(int64_t pts, const Rational &tsTimeBase=Rational(0, 0))
Set packet PTS field.
Definition: packet.cpp:228
void setDuration(int duration, const Rational &durationTimeBase=Rational(0, 0))
Definition: packet.cpp:448
void clearFlags(int flags)
Definition: packet.cpp:311
Packet()
Definition: packet.cpp:7
void addFlags(int flags)
Definition: packet.cpp:306
bool isKeyPacket() const
Definition: packet.cpp:268
void setTimeBase(const Rational &value)
Definition: packet.cpp:325
void setStreamIndex(int idx)
Definition: packet.cpp:288
bool setData(const std::vector< uint8_t > &newData, OptionalErrorCode ec=throws())
int duration() const
Definition: packet.cpp:273
bool isReferenced() const
Definition: packet.cpp:338
void swap(Packet &other)
Definition: packet.cpp:440
void setFlags(int flags)
Definition: packet.cpp:301
Packet(const std::vector< uint8_t > &data)
AVPacket makeRef(OptionalErrorCode ec=throws()) const
Definition: packet.cpp:373
Definition: rational.h:26
Definition: stream.h:23
The Timestamp class represents timestamp value and it timebase.
Definition: timestamp.h:14
Definition: audioresampler.cpp:8
Definition: ffmpeg.h:67
Definition: ffmpeg.h:107
Wrap static data, do not owning and free.
Definition: packet.h:38
Wrap data and take owning.
Definition: packet.h:33