From 22a0827dff29a94e7fd07ad2782f169b2703c70d Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 26 Oct 2012 16:36:56 +0200 Subject: [PATCH 1/5] hlsenc: stand alone hls segmenter Simplifies usage but has higher latency. --- doc/muxers.texi | 21 +++ libavformat/Makefile | 1 + libavformat/allformats.c | 2 +- libavformat/hlsenc.c | 324 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 libavformat/hlsenc.c diff --git a/doc/muxers.texi b/doc/muxers.texi index 4bb6d56a00..570041d679 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -90,6 +90,27 @@ avconv -i INPUT -c:a pcm_u8 -c:v mpeg2video -f framecrc - See also the @ref{crc} muxer. +@anchor{hls} +@section hls + +Apple HTTP Live Streaming muxer that segments MPEG-TS according to +the HTTP Live Streaming specification. + +It creates a playlist file and numbered segment files. The output +filename specifies the playlist filename; the segment filenames +receive the same basename as the playlist, a sequential number and +a .ts extension. + +@example +avconv -i in.nut out.m3u8 +@end example + +@table @option +@item -hls_time segment length in seconds +@item -hls_list_size maximum number of playlist entries +@item -hls_wrap number after which index wraps +@end table + @anchor{image2} @section image2 diff --git a/libavformat/Makefile b/libavformat/Makefile index ed030bd361..c58931679e 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -111,6 +111,7 @@ OBJS-$(CONFIG_H263_MUXER) += rawenc.o OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o OBJS-$(CONFIG_H264_MUXER) += rawenc.o OBJS-$(CONFIG_HLS_DEMUXER) += hls.o +OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o mpegtsenc.o OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o OBJS-$(CONFIG_IFF_DEMUXER) += iff.o OBJS-$(CONFIG_ILBC_DEMUXER) += ilbc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 39daec70c7..c7c4be9223 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -106,7 +106,7 @@ void av_register_all(void) REGISTER_MUXDEMUX (H261, h261); REGISTER_MUXDEMUX (H263, h263); REGISTER_MUXDEMUX (H264, h264); - REGISTER_DEMUXER (HLS, hls); + REGISTER_MUXDEMUX (HLS, hls); REGISTER_DEMUXER (IDCIN, idcin); REGISTER_DEMUXER (IFF, iff); REGISTER_MUXDEMUX (ILBC, ilbc); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c new file mode 100644 index 0000000000..88f47e0f37 --- /dev/null +++ b/libavformat/hlsenc.c @@ -0,0 +1,324 @@ +/* + * Apple HTTP Live Streaming segmenter + * Copyright (c) 2012, Luca Barbato + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/mathematics.h" +#include "libavutil/parseutils.h" +#include "libavutil/avstring.h" +#include "libavutil/opt.h" +#include "libavutil/log.h" + +#include "avformat.h" +#include "internal.h" + +typedef struct ListEntry { + char name[1024]; + int duration; + struct ListEntry *next; +} ListEntry; + +typedef struct HLSContext { + const AVClass *class; // Class for private options. + int number; + AVOutputFormat *oformat; + AVFormatContext *avf; + float time; // Set by a private option. + int size; // Set by a private option. + int wrap; // Set by a private option. + int64_t recording_time; + int has_video; + int64_t start_pts; + int64_t end_pts; + ListEntry *list; + ListEntry *end_list; + char *basename; + AVIOContext *pb; +} HLSContext; + +static int hls_mux_init(AVFormatContext *s) +{ + HLSContext *hls = s->priv_data; + AVFormatContext *oc; + int i; + + hls->avf = oc = avformat_alloc_context(); + if (!oc) + return AVERROR(ENOMEM); + + oc->oformat = hls->oformat; + oc->interrupt_callback = s->interrupt_callback; + + for (i = 0; i < s->nb_streams; i++) { + AVStream *st; + if (!(st = avformat_new_stream(oc, NULL))) + return AVERROR(ENOMEM); + avcodec_copy_context(st->codec, s->streams[i]->codec); + st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; + } + + return 0; +} + +static int append_entry(HLSContext *hls, uint64_t duration) +{ + ListEntry *en = av_malloc(sizeof(*en)); + + if (!en) + return AVERROR(ENOMEM); + + av_get_frame_filename(en->name, sizeof(en->name), hls->basename, + hls->number -1); + + en->duration = duration; + en->next = NULL; + + if (!hls->list) + hls->list = en; + else + hls->end_list->next = en; + + hls->end_list = en; + + if (hls->number >= hls->size) { + en = hls->list; + hls->list = en->next; + av_free(en); + } + + return 0; +} + +static void free_entries(HLSContext *hls) +{ + ListEntry *p = hls->list, *en; + + while(p) { + en = p; + p = p->next; + av_free(en); + } +} + +static int hls_window(AVFormatContext *s, int last) +{ + HLSContext *hls = s->priv_data; + ListEntry *en; + int ret = 0; + + if ((ret = avio_open2(&hls->pb, s->filename, AVIO_FLAG_WRITE, + &s->interrupt_callback, NULL)) < 0) + goto fail; + + avio_printf(hls->pb, "#EXTM3U\n"); + avio_printf(hls->pb, "#EXT-X-VERSION:3\n"); + avio_printf(hls->pb, "#EXT-X-TARGETDURATION:%d\n", (int)hls->time); + avio_printf(hls->pb, "#EXT-X-MEDIA-SEQUENCE:%d\n", + FFMAX(0, hls->number - hls->size)); + + for (en = hls->list; en; en = en->next) { + avio_printf(hls->pb, "#EXTINF:%d,\n", en->duration); + avio_printf(hls->pb, "%s\n", en->name); + } + + if (last) + avio_printf(hls->pb, "#EXT-X-ENDLIST\n"); + +fail: + avio_closep(&hls->pb); + return ret; +} + +static int hls_start(AVFormatContext *s) +{ + HLSContext *c = s->priv_data; + AVFormatContext *oc = c->avf; + int err = 0; + + if (c->wrap) + c->number %= c->wrap; + + if (av_get_frame_filename(oc->filename, sizeof(oc->filename), + c->basename, c->number++) < 0) + return AVERROR(EINVAL); + + if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, + &s->interrupt_callback, NULL)) < 0) + return err; + + if (oc->oformat->priv_class && oc->priv_data) + av_opt_set(oc->priv_data, "mpegts_flags", "resend_headers", 0); + + return 0; +} + +static int hls_write_header(AVFormatContext *s) +{ + HLSContext *hls = s->priv_data; + int ret, i; + char *p; + const char *pattern = "%d.ts"; + int basename_size = strlen(s->filename) + strlen(pattern); + + hls->number = 0; + + hls->recording_time = hls->time * 1000000; + hls->start_pts = AV_NOPTS_VALUE; + + for (i = 0; i < s->nb_streams; i++) + hls->has_video += + s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO; + + if (hls->has_video > 1) + av_log(s, AV_LOG_WARNING, + "More than a single video stream present, " + "expect issues decoding it.\n"); + + hls->oformat = av_guess_format("mpegts", NULL, NULL); + + if (!hls->oformat) { + ret = AVERROR_MUXER_NOT_FOUND; + goto fail; + } + + hls->basename = av_malloc(basename_size); + + if (!hls->basename) { + ret = AVERROR(ENOMEM); + goto fail; + } + + strcpy(hls->basename, s->filename); + + p = strrchr(hls->basename, '.'); + + if (p) + *p = '\0'; + + av_strlcat(hls->basename, "%d.ts", basename_size); + + if ((ret = hls_mux_init(s)) < 0) + goto fail; + + if ((ret = hls_start(s)) < 0) + goto fail; + + if ((ret = avformat_write_header(hls->avf, NULL)) < 0) + return ret; + + +fail: + if (ret) { + av_free(hls->basename); + if (hls->avf) + avformat_free_context(hls->avf); + } + return ret; +} + +static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + HLSContext *hls = s->priv_data; + AVFormatContext *oc = hls->avf; + AVStream *st = s->streams[pkt->stream_index]; + int64_t end_pts = hls->recording_time * hls->number; + int ret; + + if (hls->start_pts == AV_NOPTS_VALUE) { + hls->start_pts = pkt->pts; + hls->end_pts = pkt->pts; + } + end_pts += hls->start_pts; + + if ((hls->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + av_compare_ts(pkt->pts, st->time_base, end_pts, AV_TIME_BASE_Q) >= 0 && + pkt->flags & AV_PKT_FLAG_KEY) { + + append_entry(hls, av_rescale(pkt->pts - hls->end_pts, + st->time_base.num, + st->time_base.den)); + hls->end_pts = pkt->pts; + + av_write_frame(oc, NULL); /* Flush any buffered data */ + avio_close(oc->pb); + + ret = hls_start(s); + + if (ret) + return ret; + + oc = hls->avf; + + if ((ret = hls_window(s, 0)) < 0) + return ret; + } + + ret = ff_write_chained(oc, pkt->stream_index, pkt, s); + + return ret; +} + +static int hls_write_trailer(struct AVFormatContext *s) +{ + HLSContext *hls = s->priv_data; + AVFormatContext *oc = hls->avf; + + av_write_trailer(oc); + avio_closep(&oc->pb); + avformat_free_context(oc); + av_free(hls->basename); + hls_window(s, 1); + + free_entries(hls); + avio_close(hls->pb); + return 0; +} + +#define OFFSET(x) offsetof(HLSContext, x) +#define E AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + {"hls_time", "segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E}, + {"hls_list_size", "maximum number of playlist entries", OFFSET(size), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, + {"hls_wrap", "number after which the index wraps", OFFSET(wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E}, + { NULL }, +}; + +static const AVClass hls_class = { + .class_name = "hls muxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + + +AVOutputFormat ff_hls_muxer = { + .name = "hls", + .long_name = NULL_IF_CONFIG_SMALL("hls"), + .extensions = "m3u8", + .priv_data_size = sizeof(HLSContext), + .audio_codec = AV_CODEC_ID_MP2, + .video_codec = AV_CODEC_ID_MPEG2VIDEO, + .flags = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH, + .write_header = hls_write_header, + .write_packet = hls_write_packet, + .write_trailer = hls_write_trailer, + .priv_class = &hls_class, +}; From c1a02e884ac785033baab356a5437adf057a4189 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 12 Nov 2012 01:25:43 +0100 Subject: [PATCH 2/5] pixdesc: add av_pix_fmt_get_chroma_sub_sample Deprecate avcodec_get_chroma_sub_sample. --- cmdutils.c | 4 +++- libavcodec/avcodec.h | 6 +++++- libavcodec/ffv1enc.c | 4 ++-- libavcodec/libtheoraenc.c | 3 ++- libavcodec/mpegvideo.c | 9 +++++---- libavcodec/mpegvideo_enc.c | 10 ++++++---- libavcodec/tiffenc.c | 4 ++-- libavcodec/utils.c | 3 ++- libavcodec/vp3.c | 3 ++- libavutil/pixdesc.c | 12 ++++++++++++ libavutil/pixdesc.h | 14 ++++++++++++++ 11 files changed, 55 insertions(+), 17 deletions(-) diff --git a/cmdutils.c b/cmdutils.c index 630301ffa2..2329120c57 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1322,7 +1322,9 @@ static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbu */ memset(buf->base[0], 128, ret); - avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); + av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, + &h_chroma_shift, &v_chroma_shift); + for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { const int h_shift = i==0 ? 0 : h_chroma_shift; const int v_shift = i==0 ? 0 : v_chroma_shift; diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index d5968f9e55..58ea1bce3e 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4285,7 +4285,11 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, * @{ */ -void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift); +/** + * @deprecated Use av_pix_fmt_get_chroma_sub_sample + */ + +void attribute_deprecated avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift); /** * Return a value representing the fourCC code associated to the diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index efc1b11a85..8c6fc9a9c9 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -725,8 +725,8 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx) if (!s->transparency) s->plane_count = 2; - avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, - &s->chroma_v_shift); + av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, + &s->chroma_v_shift); s->picture_number = 0; diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c index 6c4eddf301..469c6fd467 100644 --- a/libavcodec/libtheoraenc.c +++ b/libavcodec/libtheoraenc.c @@ -197,7 +197,8 @@ static av_cold int encode_init(AVCodecContext* avc_context) av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n"); return -1; } - avcodec_get_chroma_sub_sample(avc_context->pix_fmt, &h->uv_hshift, &h->uv_vshift); + av_pix_fmt_get_chroma_sub_sample(avc_context->pix_fmt, + &h->uv_hshift, &h->uv_vshift); if (avc_context->flags & CODEC_FLAG_QSCALE) { /* to be constant with the libvorbis implementation, clip global_quality to 0 - 10 diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index af9e0403de..8a48d9937a 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -867,8 +867,9 @@ av_cold int ff_MPV_common_init(MpegEncContext *s) if (s->width && s->height) { /* set chroma shifts */ - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, - &s->chroma_y_shift); + av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, + &s->chroma_x_shift, + &s->chroma_y_shift); /* convert fourcc to upper case */ s->codec_tag = avpriv_toupper4(s->avctx->codec_tag); @@ -1781,8 +1782,8 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) (s->codec_id == AV_CODEC_ID_H264 ? 0 : 1); s->low_delay = 0; // needed to see the vectors without trashing the buffers - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, - &h_chroma_shift, &v_chroma_shift); + av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, + &h_chroma_shift, &v_chroma_shift); for (i = 0; i < 3; i++) { memcpy(s->visualization_buffer[i], pict->data[i], (i == 0) ? pict->linesize[i] * height: diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index d2719fe8ee..7c92ad2374 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -29,6 +29,7 @@ #include "libavutil/intmath.h" #include "libavutil/mathematics.h" +#include "libavutil/pixdesc.h" #include "libavutil/opt.h" #include "avcodec.h" #include "dsputil.h" @@ -601,8 +602,8 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) if (avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) s->inter_quant_bias = avctx->inter_quant_bias; - avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, - &chroma_v_shift); + av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, + &chroma_v_shift); if (avctx->codec_id == AV_CODEC_ID_MPEG4 && s->avctx->time_base.den > (1 << 16) - 1) { @@ -994,8 +995,9 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) // empty } else { int h_chroma_shift, v_chroma_shift; - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, - &v_chroma_shift); + av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, + &h_chroma_shift, + &v_chroma_shift); for (i = 0; i < 3; i++) { int src_stride = pic_arg->linesize[i]; diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index 9811404313..8162c407d6 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -270,8 +270,8 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, case AV_PIX_FMT_YUV410P: case AV_PIX_FMT_YUV411P: s->photometric_interpretation = 6; - avcodec_get_chroma_sub_sample(avctx->pix_fmt, - &shift_h, &shift_v); + av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, + &shift_h, &shift_v); s->bpp = 8 + (16 >> (shift_h + shift_v)); s->subsampling[0] = 1 << shift_h; s->subsampling[1] = 1 << shift_v; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 8c203b92fb..054dc693e9 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -427,7 +427,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt); const int pixel_size = desc->comp[0].step_minus1 + 1; - avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); + av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, + &v_chroma_shift); avcodec_align_dimensions2(s, &w, &h, stride_align); diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 90532cbe54..e8127597c6 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -1687,7 +1687,8 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) for (i = 0; i < 3; i++) s->qps[i] = -1; - avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); + av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, + &s->chroma_y_shift); s->y_superblock_width = (s->width + 31) / 32; s->y_superblock_height = (s->height + 31) / 32; diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index bc446b1fab..d0889b4b38 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -1454,3 +1454,15 @@ enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc) return desc - av_pix_fmt_descriptors; } + +int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, + int *h_shift, int *v_shift) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + if (!desc) + return AVERROR(ENOSYS); + *h_shift = desc->log2_chroma_w; + *v_shift = desc->log2_chroma_h; + + return 0; +} diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h index 7da17bcf12..a944c66dd3 100644 --- a/libavutil/pixdesc.h +++ b/libavutil/pixdesc.h @@ -203,4 +203,18 @@ const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev); */ enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc); +/** + * Utility function to access log2_chroma_w log2_chroma_h from + * the pixel format AVPixFmtDescriptor. + * + * @param[in] pix_fmt the pixel format + * @param[out] h_shift store log2_chroma_h + * @param[out] v_shift store log2_chroma_w + * + * @return 0 on success, AVERROR(ENOSYS) on invalid or unknown pixel format + */ +int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, + int *h_shift, int *v_shift); + + #endif /* AVUTIL_PIXDESC_H */ From cc085993f42cc01f394c2ce867397179bdf17cca Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 12 Nov 2012 01:25:44 +0100 Subject: [PATCH 3/5] avcodec: remove ff_is_hwaccel_pix_fmt It is used only in one place and is unlikely it would be needed elsewhere. --- libavcodec/imgconvert.c | 6 ------ libavcodec/internal.h | 5 ----- libavcodec/utils.c | 8 +++++++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index fd30dc4596..dacf3c46bf 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -415,12 +415,6 @@ void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift = desc->log2_chroma_h; } -int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt) -{ - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); - return desc->flags & PIX_FMT_HWACCEL; -} - int avpicture_fill(AVPicture *picture, uint8_t *ptr, enum AVPixelFormat pix_fmt, int width, int height) { diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 231d4b6809..0f624e201f 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -85,11 +85,6 @@ struct AVCodecDefault { const uint8_t *value; }; -/** - * Determine whether pix_fmt is a hardware accelerated format. - */ -int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt); - /** * Return the hardware accelerated codec for codec codec_id and * pixel format pix_fmt. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 054dc693e9..06f4fc94e4 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -628,9 +628,15 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, return 0; } +static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + return desc->flags & PIX_FMT_HWACCEL; +} + enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt) { - while (*fmt != AV_PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt)) + while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt)) ++fmt; return fmt[0]; } From 83f9ed42ec696cedd7b84f255968a5888f749fc9 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 13 Nov 2012 17:42:13 +0100 Subject: [PATCH 4/5] libtheoraenc: add missing pixdesc.h header Was left out from c1a02e884ac785033baab356a5437adf057a4189. --- libavcodec/libtheoraenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c index 469c6fd467..e57310ac33 100644 --- a/libavcodec/libtheoraenc.c +++ b/libavcodec/libtheoraenc.c @@ -33,6 +33,7 @@ /* Libav includes */ #include "libavutil/common.h" #include "libavutil/intreadwrite.h" +#include "libavutil/pixdesc.h" #include "libavutil/log.h" #include "libavutil/base64.h" #include "avcodec.h" From 5e9c6ef8f3beb9ed7b271654a82349ac90fe43f2 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 15 Jul 2012 15:44:39 +0200 Subject: [PATCH 5/5] x86: h264_weight_10bit: port to cpuflags --- libavcodec/x86/h264_weight_10bit.asm | 132 ++++++++++++++------------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/libavcodec/x86/h264_weight_10bit.asm b/libavcodec/x86/h264_weight_10bit.asm index 20d26a49c3..3b09e420d2 100644 --- a/libavcodec/x86/h264_weight_10bit.asm +++ b/libavcodec/x86/h264_weight_10bit.asm @@ -48,7 +48,7 @@ SECTION .text movifnidn r5d, r5m %endmacro -%macro WEIGHT_SETUP 1 +%macro WEIGHT_SETUP 0 mova m0, [pw_1] movd m2, r3m pslld m0, m2 ; 1<