GUACAMOLE-465: resolved issues brought up in PR159 (unneeded dynamic mem allocation, style guide violations)

This commit is contained in:
Sean Reid 2018-03-12 20:47:11 -04:00 committed by Sean Reid
parent bb825de73b
commit fb237d4fc9
3 changed files with 17 additions and 39 deletions

View File

@ -52,17 +52,14 @@
static int guacenc_write_packet(guacenc_video* video, void* data, int size) { static int guacenc_write_packet(guacenc_video* video, void* data, int size) {
int ret; int ret;
AVPacket *pkt;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,1,0) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,1,0)
AVPacket pkt;
pkt = malloc(sizeof(AVPacket));
/* have to create a packet around the encoded data we have */ /* have to create a packet around the encoded data we have */
av_init_packet(pkt); av_init_packet(&pkt);
if (video->context->coded_frame->pts != AV_NOPTS_VALUE) { if (video->context->coded_frame->pts != AV_NOPTS_VALUE) {
pkt->pts = av_rescale_q(video->context->coded_frame->pts, pkt.pts = av_rescale_q(video->context->coded_frame->pts,
video->context->time_base, video->context->time_base,
video->output_stream->time_base); video->output_stream->time_base);
} }
@ -70,13 +67,13 @@ static int guacenc_write_packet(guacenc_video* video, void* data, int size) {
pkt->flags |= AV_PKT_FLAG_KEY; pkt->flags |= AV_PKT_FLAG_KEY;
} }
pkt->data = data; pkt.data = data;
pkt->size = size; pkt.size = size;
pkt->stream_index = video->output_stream->index; pkt.stream_index = video->output_stream->index;
ret = av_interleaved_write_frame(video->container_format_context, pkt); ret = av_interleaved_write_frame(video->container_format_context, &pkt);
free(pkt);
#else #else
AVPacket *pkt;
/* we know data is already a packet if we're using a newer libavcodec */ /* we know data is already a packet if we're using a newer libavcodec */
pkt = (AVPacket*) data; pkt = (AVPacket*) data;
av_packet_rescale_ts(pkt, video->context->time_base, video->output_stream->time_base); av_packet_rescale_ts(pkt, video->context->time_base, video->output_stream->time_base);
@ -197,16 +194,10 @@ int guacenc_avcodec_encode_video(guacenc_video* video, AVFrame* frame) {
#endif #endif
} }
AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
AVCodec* codec, int bitrate, int width, int height, int gop_size, int qmax, int qmin,
int bitrate, int pix_fmt, AVRational time_base) {
int width,
int height,
int gop_size,
int qmax,
int qmin,
int pix_fmt,
AVRational time_base) {
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57, 33, 100) #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(57, 33, 100)
stream->codec->bit_rate = bitrate; stream->codec->bit_rate = bitrate;
stream->codec->width = width; stream->codec->width = width;

View File

@ -113,16 +113,9 @@ int guacenc_avcodec_encode_video(guacenc_video* video, AVFrame* frame);
* The target time base for the encoded video * The target time base for the encoded video
* *
*/ */
AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodecContext* guacenc_build_avcodeccontext(AVStream* stream, AVCodec* codec,
AVCodec* codec, int bitrate, int width, int height, int gop_size, int qmax, int qmin,
int bitrate, int pix_fmt, AVRational time_base);
int width,
int height,
int gop_size,
int qmax,
int qmin,
int pix_fmt,
AVRational time_base);
/** /**
* A wrapper for avcodec_open2(). Because libavformat ver * A wrapper for avcodec_open2(). Because libavformat ver

View File

@ -80,14 +80,8 @@ guacenc_video* guacenc_video_alloc(const char* path, const char* codec_name,
/* Retrieve encoding context */ /* Retrieve encoding context */
AVCodecContext* avcodec_context = AVCodecContext* avcodec_context =
guacenc_build_avcodeccontext(video_stream, guacenc_build_avcodeccontext(video_stream, codec, bitrate, width,
codec, height, /*gop size*/ 10, /*qmax*/ 31, /*qmin*/ 2,
bitrate,
width,
height,
/*gop size*/ 10,
/*qmax*/ 31,
/*qmin*/ 2,
/*pix fmt*/ AV_PIX_FMT_YUV420P, /*pix fmt*/ AV_PIX_FMT_YUV420P,
/*time base*/ (AVRational) { 1, GUACENC_VIDEO_FRAMERATE }); /*time base*/ (AVRational) { 1, GUACENC_VIDEO_FRAMERATE });