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

Fixing crashes

parent bf97dc85
......@@ -33,8 +33,8 @@ using namespace std;
namespace mediastreamer {
// Public methods
MediaCodecEncoderFilterImpl::MediaCodecEncoderFilterImpl(MSFilter *f, const string &mime, NalPacker *packer):
_f(f), _mime(mime), _packer(packer) {
MediaCodecEncoderFilterImpl::MediaCodecEncoderFilterImpl(MSFilter *f, const std::string &mime, int profile, int level, NalPacker *packer, const MSVideoConfiguration *vconfs):
_f(f), _mime(mime), _profile(profile), _level(level), _packer(packer), _vconfList(vconfs) {
_vconf = ms_video_find_best_configuration_for_size(_vconfList, MS_VIDEO_SIZE_CIF, ms_factory_get_cpu_count(f->factory));
ms_video_starter_init(&_starter);
......
......@@ -34,7 +34,6 @@ namespace mediastreamer {
class MediaCodecEncoderFilterImpl {
public:
MediaCodecEncoderFilterImpl(MSFilter *f, const std::string &mime, NalPacker *packer);
virtual ~MediaCodecEncoderFilterImpl();
virtual void preprocess();
......@@ -59,21 +58,23 @@ public:
void notifyFir();
protected:
MediaCodecEncoderFilterImpl(MSFilter *f, const std::string &mime, int profile, int level, NalPacker *packer, const MSVideoConfiguration *vconfs);
virtual void onFrameEncodedHook(MSQueue *frame) {};
media_status_t allocEncoder();
media_status_t tryColorFormat(AMediaFormat *format, unsigned value);
int encConfigure();
MSFilter *_f = nullptr;
std::string _mime;
int _profile = 0;
int _level = 0;
std::unique_ptr<NalPacker> _packer;
const MSVideoConfiguration *_vconfList;
MSVideoConfiguration _vconf;
bool _avpfEnabled = false;
int _profile = 0;
int _level = 0;
MSFilter *_f = nullptr;
std::string _mime;
std::unique_ptr<NalPacker> _packer;
AMediaCodec *_codec = nullptr;
uint64_t _framenum = 0;
MSVideoStarter _starter;
......
......@@ -21,20 +21,20 @@
#include "h264utils.h"
#include "media-codec-encoder.h"
#define MS_MEDIACODECH264_CONF(required_bitrate, bitrate_limit, resolution, fps, ncpus) \
#define MS_MEDIACODECH265_CONF(required_bitrate, bitrate_limit, resolution, fps, ncpus) \
{ required_bitrate, bitrate_limit, { MS_VIDEO_SIZE_ ## resolution ## _W, MS_VIDEO_SIZE_ ## resolution ## _H }, fps, ncpus, nullptr }
static const MSVideoConfiguration _media_codec_h264_conf_list[] = {
MS_MEDIACODECH264_CONF(2048000, 1000000, UXGA, 25, 2),
MS_MEDIACODECH264_CONF(1024000, 5000000, SXGA_MINUS, 25, 2),
MS_MEDIACODECH264_CONF(1024000, 5000000, 720P, 30, 2),
MS_MEDIACODECH264_CONF( 750000, 2048000, XGA, 25, 2),
MS_MEDIACODECH264_CONF( 500000, 1024000, SVGA, 15, 2),
MS_MEDIACODECH264_CONF( 600000, 3000000, VGA, 30, 2),
MS_MEDIACODECH264_CONF( 400000, 800000, VGA, 15, 2),
MS_MEDIACODECH264_CONF( 128000, 512000, CIF, 15, 1),
MS_MEDIACODECH264_CONF( 100000, 380000, QVGA, 15, 1),
MS_MEDIACODECH264_CONF( 0, 170000, QCIF, 10, 1),
MS_MEDIACODECH265_CONF(2048000, 1000000, UXGA, 25, 2),
MS_MEDIACODECH265_CONF(1024000, 5000000, SXGA_MINUS, 25, 2),
MS_MEDIACODECH265_CONF(1024000, 5000000, 720P, 30, 2),
MS_MEDIACODECH265_CONF( 750000, 2048000, XGA, 25, 2),
MS_MEDIACODECH265_CONF( 500000, 1024000, SVGA, 15, 2),
MS_MEDIACODECH265_CONF( 600000, 3000000, VGA, 30, 2),
MS_MEDIACODECH265_CONF( 400000, 800000, VGA, 15, 2),
MS_MEDIACODECH265_CONF( 128000, 512000, CIF, 15, 1),
MS_MEDIACODECH265_CONF( 100000, 380000, QVGA, 15, 1),
MS_MEDIACODECH265_CONF( 0, 170000, QCIF, 10, 1),
};
namespace mediastreamer {
......@@ -42,11 +42,13 @@ namespace mediastreamer {
class MediaCodecH264EncoderFilterImpl: public MediaCodecEncoderFilterImpl {
public:
MediaCodecH264EncoderFilterImpl(MSFilter *f): MediaCodecEncoderFilterImpl(f, "video/avc", new H264NalPacker()) {
_vconfList = _media_codec_h264_conf_list;
_profile = 1; // AVCProfileBaseline
_level = 1024; // AVCLevel32
}
MediaCodecH264EncoderFilterImpl(MSFilter *f): MediaCodecEncoderFilterImpl(
f,
"video/avc",
1, // AVCProfileBaseline
1024, // AVCLevel32
new H264NalPacker(),
_media_codec_h264_conf_list) {}
~MediaCodecH264EncoderFilterImpl() {
if (_sps) freemsg(_sps);
......
......@@ -20,14 +20,33 @@
#include "h265-nal-packer.h"
#include "media-codec-encoder.h"
#define MS_MEDIACODECH265_CONF(required_bitrate, bitrate_limit, resolution, fps, ncpus) \
{ required_bitrate, bitrate_limit, { MS_VIDEO_SIZE_ ## resolution ## _W, MS_VIDEO_SIZE_ ## resolution ## _H }, fps, ncpus, nullptr }
static const MSVideoConfiguration _media_codec_h265_conf_list[] = {
MS_MEDIACODECH265_CONF(2048000, 1000000, UXGA, 25, 2),
MS_MEDIACODECH265_CONF(1024000, 5000000, SXGA_MINUS, 25, 2),
MS_MEDIACODECH265_CONF(1024000, 5000000, 720P, 30, 2),
MS_MEDIACODECH265_CONF( 750000, 2048000, XGA, 25, 2),
MS_MEDIACODECH265_CONF( 500000, 1024000, SVGA, 15, 2),
MS_MEDIACODECH265_CONF( 600000, 3000000, VGA, 30, 2),
MS_MEDIACODECH265_CONF( 400000, 800000, VGA, 15, 2),
MS_MEDIACODECH265_CONF( 128000, 512000, CIF, 15, 1),
MS_MEDIACODECH265_CONF( 100000, 380000, QVGA, 15, 1),
MS_MEDIACODECH265_CONF( 0, 170000, QCIF, 10, 1),
};
namespace mediastreamer {
class MediaCodecH265EncoderFilterImpl: public MediaCodecEncoderFilterImpl {
public:
MediaCodecH265EncoderFilterImpl(MSFilter *f): MediaCodecEncoderFilterImpl(f, "video/hevc", new H265NalPacker(f->factory)) {
_profile = 1; // HEVCProfileMain
_level = 256; // HEVCMainTierLevel31
}
MediaCodecH265EncoderFilterImpl(MSFilter *f): MediaCodecEncoderFilterImpl(
f,
"video/hevc",
1, // HEVCProfileMain
256, // HEVCMainTierLevel31
new H265NalPacker(f->factory),
_media_codec_h265_conf_list) {}
static void onFilterInit(MSFilter *f) {
f->data = new MediaCodecH265EncoderFilterImpl(f);
......
......@@ -78,7 +78,7 @@ void H265FuHeader::parse(const uint8_t *header) {
header2 >>= 1;
bool start = ((header2 & 0x01) != 0);
if (start && end) throw runtime_error("parsing an FU header with both start and end flags enabled");
if (start && end) throw invalid_argument("parsing an FU header with both start and end flags enabled");
if (start) {
_pos = Position::Start;
......@@ -97,8 +97,7 @@ mblk_t *H265FuHeader::forge() const {
header |= _type;
mblk_t *newHeader = allocb(1, 0);
*newHeader->b_wptr = header;
newHeader++;
*newHeader->b_wptr++ = header;
return newHeader;
}
......
......@@ -26,7 +26,7 @@ namespace mediastreamer {
class H265NalPacker: public NalPacker {
public:
H265NalPacker(const MSFactory *factory): NalPacker(new NaluAggregator, new NaluSpliter(), factory) {}
H265NalPacker(const MSFactory *factory): NalPacker(new NaluAggregator(), new NaluSpliter(), factory) {}
private:
class NaluAggregator: public NaluAggregatorInterface {
......
......@@ -31,7 +31,8 @@ void NalPacker::NaluAggregatorInterface::setMaxSize(size_t maxSize) {
_maxSize = maxSize;
}
NalPacker::NalPacker(NaluAggregatorInterface *naluAggregator, NaluSpliterInterface *naluSpliter, const MSFactory *factory) {
NalPacker::NalPacker(NaluAggregatorInterface *naluAggregator, NaluSpliterInterface *naluSpliter, const MSFactory *factory):
_naluSpliter(naluSpliter), _naluAggregator(naluAggregator) {
setMaxPayloadSize(ms_factory_get_payload_max_size(factory));
}
......
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