Commit b2be6120 authored by François Grisez's avatar François Grisez
Browse files

Reworking of NalPacker interface.

parent 561df979
......@@ -17,8 +17,6 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <exception>
#include "h264utils.h"
#include "h264-nal-packer.h"
......@@ -30,20 +28,13 @@ namespace mediastreamer {
// H264NaluToStapAggregator
// ========================
void H264NaluAggregator::setMaxSize(size_t maxSize) {
if (isAggregating()) {
throw logic_error("changing payload size while aggregating NALus into a STAP-A");
}
_maxsize = maxSize;
}
mblk_t *H264NaluAggregator::feed(mblk_t *nalu) {
size_t size = msgdsize(nalu);
if (_stap == nullptr) {
_stap = nalu;
_size = size + 3; /* STAP-A header + size */
} else {
if ((_size + size) < (_maxsize - 2)) {
if ((_size + size) < (_maxSize - 2)) {
_stap = concatNalus(_stap, nalu);
_size += (size + 2); /* +2 for the STAP-A size field */
} else {
......@@ -99,7 +90,7 @@ void H264NaluAggregator::putNalSize(mblk_t *m, size_t sz) {
void H264NaluSpliter::feed(mblk_t *nalu) {
mblk_t *m;
int payload_max_size = _maxsize - 2; /*minus FU-A header*/
int payload_max_size = _maxSize - 2; /*minus FU-A header*/
uint8_t fu_indicator;
uint8_t type = ms_h264_nalu_get_type(nalu);
uint8_t nri = ms_h264_nalu_get_nri(nalu);
......
......@@ -28,11 +28,8 @@ public:
H264NaluAggregator() {}
~H264NaluAggregator() {reset();}
size_t getMaxSize() const override {return _maxsize;}
void setMaxSize(size_t maxSize) override;
mblk_t *feed(mblk_t *nalu) override;
bool isAggregating() const override {return bool(_stap);}
bool isAggregating() const override {return _stap != nullptr;}
void reset() override;
mblk_t *completeAggregation() override;
......@@ -43,23 +40,11 @@ private:
mblk_t *_stap = nullptr;
size_t _size = 0;
size_t _maxsize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
};
class H264NaluSpliter: public NalPacker::NaluSpliterInterface {
public:
H264NaluSpliter() {ms_queue_init(&_q);}
~H264NaluSpliter() {ms_queue_flush(&_q);}
size_t getMaxSize() const override {return _maxsize;}
void setMaxSize(size_t maxSize) override {_maxsize = maxSize;}
void feed(mblk_t *nalu) override;
MSQueue *getPackets() override {return &_q;};
private:
size_t _maxsize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
MSQueue _q;
};
class H264NalPacker: public NalPacker {
......
......@@ -30,9 +30,6 @@ private:
public:
~NaluAggregator();
size_t getMaxSize() const override {return _maxSize;}
void setMaxSize(size_t maxSize) override {_maxSize = maxSize;}
mblk_t *feed(mblk_t *nalu) override;
bool isAggregating() const override {return _ap != nullptr;}
void reset() override;
......@@ -42,7 +39,6 @@ private:
void placeFirstNalu(mblk_t *nalu);
void aggregate(mblk_t *nalu);
size_t _maxSize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
size_t _size = 0;
H265NaluHeader _apHeader;
mblk_t *_ap = nullptr;
......@@ -50,20 +46,10 @@ private:
class NaluSpliter: public NaluSpliterInterface {
public:
NaluSpliter() {ms_queue_init(&_q);}
~NaluSpliter() {ms_queue_flush(&_q);}
size_t getMaxSize() const override {return _maxSize;}
void setMaxSize(size_t maxSize) override {_maxSize = maxSize;}
void feed(mblk_t *nalu) override;
MSQueue *getPackets() override {return &_q;}
private:
mblk_t *makeFu(const H265NaluHeader &naluHeader, const H265FuHeader &fuHeader, const uint8_t *payload, size_t length);
size_t _maxSize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
MSQueue _q;
};
H265NalPacker(const MSFactory *factory): NalPacker(new NaluAggregator, new NaluSpliter(), factory) {}
......
......@@ -17,10 +17,20 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdexcept>
#include "nal-packer.h"
using namespace std;
namespace mediastreamer {
void NalPacker::NaluAggregatorInterface::setMaxSize(size_t maxSize) {
if (isAggregating()) {
throw logic_error("changing payload size while aggregating NALus");
}
_maxSize = maxSize;
}
NalPacker::NalPacker(NaluAggregatorInterface *naluAggregator, NaluSpliterInterface *naluSpliter, const MSFactory *factory) {
setMaxPayloadSize(ms_factory_get_payload_max_size(factory));
}
......
......@@ -36,24 +36,32 @@ public:
public:
virtual ~NaluAggregatorInterface() = default;
virtual size_t getMaxSize() const = 0;
virtual void setMaxSize(size_t maxSize) = 0;
size_t getMaxSize() const {return _maxSize;}
void setMaxSize(size_t maxSize);
virtual mblk_t *feed(mblk_t *nalu) = 0;
virtual bool isAggregating() const = 0;
virtual void reset() = 0;
virtual mblk_t *completeAggregation() = 0;
protected:
size_t _maxSize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
};
class NaluSpliterInterface {
public:
virtual ~NaluSpliterInterface() = default;
NaluSpliterInterface() {ms_queue_init(&_q);}
virtual ~NaluSpliterInterface() {ms_queue_flush(&_q);}
virtual size_t getMaxSize() const = 0;
virtual void setMaxSize(size_t maxSize) = 0;
size_t getMaxSize() const {return _maxSize;}
void setMaxSize(size_t maxSize) {_maxSize = maxSize;}
virtual void feed(mblk_t *nalu) = 0;
virtual MSQueue *getPackets() = 0;
MSQueue *getPackets() {return &_q;}
protected:
size_t _maxSize = MS_DEFAULT_MAX_PAYLOAD_SIZE;
MSQueue _q;
};
void setPacketizationMode(PacketizationMode packMode) {_packMode = packMode;}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment