summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/amrwbdec.c2
-rw-r--r--libavcodec/avcodec.h20
-rw-r--r--libavcodec/codec_desc.c13
-rw-r--r--libavcodec/mpegvideo_enc.c31
-rw-r--r--libavcodec/options.c6
-rw-r--r--libavcodec/utils.c11
6 files changed, 60 insertions, 23 deletions
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index d97cbc5ae2..43f2044b8f 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -133,7 +133,7 @@ static int decode_mime_header(AMRWBContext *ctx, const uint8_t *buf)
{
/* Decode frame header (1st octet) */
ctx->fr_cur_mode = buf[0] >> 3 & 0x0F;
- ctx->fr_quality = (buf[0] & 0x4) != 0x4;
+ ctx->fr_quality = (buf[0] & 0x4) == 0x4;
return 1;
}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 372d0cfe4e..1115caf23d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1440,7 +1440,7 @@ typedef struct AVCodecContext {
int log_level_offset;
enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
- struct AVCodec *codec;
+ const struct AVCodec *codec;
char codec_name[32];
enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
@@ -3338,7 +3338,7 @@ typedef struct AVSubtitle {
* if c is non-NULL, returns the next registered codec after c,
* or NULL if c is the last one.
*/
-AVCodec *av_codec_next(AVCodec *c);
+AVCodec *av_codec_next(const AVCodec *c);
/**
* Return the LIBAVCODEC_VERSION_INT constant.
@@ -3426,7 +3426,7 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
* @return An AVCodecContext filled with default values or NULL on failure.
* @see avcodec_get_context_defaults
*/
-AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
+AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
/**
* Set the fields of the given AVCodecContext to default values corresponding
@@ -3437,7 +3437,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
* If codec is non-NULL, it is illegal to call avcodec_open2() with a
* different codec on this AVCodecContext.
*/
-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
+int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
/**
* Get the AVClass for AVCodecContext. It can be used in combination with
@@ -3562,7 +3562,7 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
* @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
* av_dict_set(), av_opt_find().
*/
-int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options);
+int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
/**
* Close a given AVCodecContext and free all the data associated with it
@@ -4834,12 +4834,12 @@ int avcodec_is_open(AVCodecContext *s);
/**
* @return a non-zero number if codec is an encoder, zero otherwise
*/
-int av_codec_is_encoder(AVCodec *codec);
+int av_codec_is_encoder(const AVCodec *codec);
/**
* @return a non-zero number if codec is a decoder, zero otherwise
*/
-int av_codec_is_decoder(AVCodec *codec);
+int av_codec_is_decoder(const AVCodec *codec);
/**
* @return descriptor for given codec ID or NULL if no descriptor exists.
@@ -4856,6 +4856,12 @@ const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id);
const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
/**
+ * @return codec descriptor with the given name or NULL if no such descriptor
+ * exists.
+ */
+const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
+
+/**
* @}
*/
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index d702b7faf3..607eaab84a 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <string.h>
+
#include "avcodec.h"
#include "libavutil/common.h"
@@ -2122,3 +2124,14 @@ const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev)
return prev + 1;
return NULL;
}
+
+const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name)
+{
+ const AVCodecDescriptor *desc = NULL;
+
+ while ((desc = avcodec_descriptor_next(desc))) {
+ if (!strcmp(desc->name, name))
+ return desc;
+ }
+ return NULL;
+}
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6798061116..bf144affe9 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1120,6 +1120,22 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref)
return 0;
}
+static int encode_frame(AVCodecContext *c, AVFrame *frame)
+{
+ AVPacket pkt = { 0 };
+ int ret, got_output;
+
+ av_init_packet(&pkt);
+ av_init_packet(&pkt);
+ ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
+ if (ret < 0)
+ return ret;
+
+ ret = pkt.size;
+ av_free_packet(&pkt);
+ return ret;
+}
+
static int estimate_best_b_count(MpegEncContext *s)
{
AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
@@ -1127,8 +1143,6 @@ static int estimate_best_b_count(MpegEncContext *s)
AVFrame input[FF_MAX_B_FRAMES + 2];
const int scale = s->avctx->brd_scale;
int i, j, out_size, p_lambda, b_lambda, lambda2;
- int outbuf_size = s->width * s->height; // FIXME
- uint8_t *outbuf = av_malloc(outbuf_size);
int64_t best_rd = INT64_MAX;
int best_b_count = -1;
@@ -1205,8 +1219,9 @@ static int estimate_best_b_count(MpegEncContext *s)
input[0].pict_type = AV_PICTURE_TYPE_I;
input[0].quality = 1 * FF_QP2LAMBDA;
- out_size = avcodec_encode_video(c, outbuf,
- outbuf_size, &input[0]);
+
+ out_size = encode_frame(c, &input[0]);
+
//rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;
for (i = 0; i < s->max_b_frames + 1; i++) {
@@ -1215,14 +1230,15 @@ static int estimate_best_b_count(MpegEncContext *s)
input[i + 1].pict_type = is_p ?
AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;
input[i + 1].quality = is_p ? p_lambda : b_lambda;
- out_size = avcodec_encode_video(c, outbuf, outbuf_size,
- &input[i + 1]);
+
+ out_size = encode_frame(c, &input[i + 1]);
+
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
}
/* get the delayed frames */
while (out_size) {
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
+ out_size = encode_frame(c, NULL);
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
}
@@ -1234,7 +1250,6 @@ static int estimate_best_b_count(MpegEncContext *s)
}
}
- av_freep(&outbuf);
avcodec_close(c);
av_freep(&c);
diff --git a/libavcodec/options.c b/libavcodec/options.c
index e64bc9edf8..cd30229e19 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -94,7 +94,8 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_typ
}
#endif
-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
+int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
+{
int flags=0;
memset(s, 0, sizeof(AVCodecContext));
@@ -146,7 +147,8 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
return 0;
}
-AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
+AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
+{
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
if(avctx==NULL) return NULL;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 53759f2e6f..a96b52d638 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -115,7 +115,8 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
/* encoder management */
static AVCodec *first_avcodec = NULL;
-AVCodec *av_codec_next(AVCodec *c){
+AVCodec *av_codec_next(const AVCodec *c)
+{
if(c) return c->next;
else return first_avcodec;
}
@@ -131,12 +132,12 @@ static void avcodec_init(void)
ff_dsputil_static_init();
}
-int av_codec_is_encoder(AVCodec *codec)
+int av_codec_is_encoder(const AVCodec *codec)
{
return codec && (codec->encode || codec->encode2);
}
-int av_codec_is_decoder(AVCodec *codec)
+int av_codec_is_decoder(const AVCodec *codec)
{
return codec && codec->decode;
}
@@ -750,7 +751,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
}
#endif
-int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
+int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
{
int ret = 0;
AVDictionary *tmp = NULL;
@@ -1888,7 +1889,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
const char *codec_type;
const char *codec_name;
const char *profile = NULL;
- AVCodec *p;
+ const AVCodec *p;
int bitrate;
AVRational display_aspect_ratio;