Esempio n. 1
0
static bool get_codecs(const AVCodecDescriptor*** descs, unsigned int *size)
{
	const AVCodecDescriptor *desc = NULL;
	const AVCodecDescriptor **codecs;
	unsigned int codec_count = 0;
	unsigned int i = 0;

	while ((desc = avcodec_descriptor_next(desc)))
		codec_count++;

	codecs = av_calloc(codec_count, sizeof(AVCodecDescriptor *));

	if (codecs == NULL) {
		av_log(NULL, AV_LOG_ERROR, "unable to allocate sorted codec "
				"array with size %d", codec_count);
		return false;
	}

	while ((desc = avcodec_descriptor_next(desc)))
		codecs[i++] = desc;

	*size = codec_count;
	*descs = codecs;
	return true;
}
Esempio n. 2
0
static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
{
    const AVCodecDescriptor *desc = NULL;
    const AVCodecDescriptor **codecs;
    unsigned nb_codecs = 0, i = 0;
	
    while ((desc = avcodec_descriptor_next(desc)))
        ++nb_codecs;
    if (!(codecs = (const AVCodecDescriptor**) av_calloc(nb_codecs, sizeof(*codecs)))) {
        av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
        exit(1);
    }
    desc = NULL;
    while ((desc = avcodec_descriptor_next(desc)))
        codecs[i++] = desc;
    av_assert0(i == nb_codecs);
    qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
    *rcodecs = codecs;
    return nb_codecs;
}