History

Merge commit 'dd2d3b766b20196d0b65a82e3d897ccecbf7adb8'

* commit 'dd2d3b766b20196d0b65a82e3d897ccecbf7adb8': lavc: Add hwaccel private data and init/uninit callbacks Conflicts: libavcodec/avcodec.h libavcodec/internal.h libavcodec/pthread_frame.c

Michael Niedermayer committed 12 years ago

Commit 2ec45862 parents c4fe50b dd2d3b74 files · +59 −4Browse files

Unified · Split

4 files
  1. libavcodec/avcodec.h +23 −0
  2. libavcodec/internal.h +5 −0
  3. libavcodec/pthread_frame.c +1 −0
  4. libavcodec/utils.c +30 −4
libavcodec/avcodec.h+23−0
@@ -3307,6 +3307,29 @@ typedef struct AVHWAccel { · 3306 unmodified lines
33073307 * @param s the mpeg context
33083308 */
33093309 void (*decode_mb)(struct MpegEncContext *s);
3310+
3311+ /**
3312+ * Initialize the hwaccel private data.
3313+ *
3314+ * This will be called from ff_get_format(), after hwaccel and
3315+ * hwaccel_context are set and the hwaccel private data in AVCodecInternal
3316+ * is allocated.
3317+ */
3318+ int (*init)(AVCodecContext *avctx);
3319+
3320+ /**
3321+ * Uninitialize the hwaccel private data.
3322+ *
3323+ * This will be called from get_format() or avcodec_close(), after hwaccel
3324+ * and hwaccel_context are already uninitialized.
3325+ */
3326+ int (*uninit)(AVCodecContext *avctx);
3327+
3328+ /**
3329+ * Size of the private data to allocate in
3330+ * AVCodecInternal.hwaccel_priv_data.
3331+ */
3332+ int priv_data_size;
33103333 } AVHWAccel;
33113334
33123335 /**
libavcodec/internal.h+5−0
@@ -122,6 +122,11 @@ typedef struct AVCodecInternal { · 121 unmodified lines
122122 * Number of audio samples to skip at the start of the next decoded frame
123123 */
124124 int skip_samples;
125+
126+ /**
127+ * hwaccel-specific private data
128+ */
129+ void *hwaccel_priv_data;
125130 } AVCodecInternal;
126131
127132 struct AVCodecDefault {
libavcodec/pthread_frame.c+1−0
@@ -226,6 +226,7 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, · 225 unmodified lines
226226 dst->sample_rate = src->sample_rate;
227227 dst->sample_fmt = src->sample_fmt;
228228 dst->channel_layout = src->channel_layout;
229+ dst->internal->hwaccel_priv_data = src->internal->hwaccel_priv_data;
229230 }
230231
231232 if (for_user) {
libavcodec/utils.c+30−4
@@ -1146,16 +1146,37 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) · 1145 unmodified lines
11461146 if (!desc)
11471147 return AV_PIX_FMT_NONE;
11481148
1149+ if (avctx->hwaccel && avctx->hwaccel->uninit)
1150+ avctx->hwaccel->uninit(avctx);
1151+ av_freep(&avctx->internal->hwaccel_priv_data);
1152+ avctx->hwaccel = NULL;
1153+
11491154 if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1150− avctx->hwaccel = find_hwaccel(avctx->codec_id, ret);
1151− if (!avctx->hwaccel) {
1155+ AVHWAccel *hwaccel;
1156+ int err;
1157+
1158+ hwaccel = find_hwaccel(avctx->codec_id, ret);
1159+ if (!hwaccel) {
11521160 av_log(avctx, AV_LOG_ERROR,
11531161 "Could not find an AVHWAccel for the pixel format: %s",
11541162 desc->name);
11551163 return AV_PIX_FMT_NONE;
11561164 }
1157− } else {
1158− avctx->hwaccel = NULL;
1165+
1166+ if (hwaccel->priv_data_size) {
1167+ avctx->internal->hwaccel_priv_data = av_mallocz(hwaccel->priv_data_size);
1168+ if (!avctx->internal->hwaccel_priv_data)
1169+ return AV_PIX_FMT_NONE;
1170+ }
1171+
1172+ if (hwaccel->init) {
1173+ err = hwaccel->init(avctx);
1174+ if (err < 0) {
1175+ av_freep(&avctx->internal->hwaccel_priv_data);
1176+ return AV_PIX_FMT_NONE;
1177+ }
1178+ }
1179+ avctx->hwaccel = hwaccel;
11591180 }
11601181
11611182 return ret;
@@ -2689,6 +2710,11 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 1527 unmodified lines
26892710 for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
26902711 av_buffer_pool_uninit(&pool->pools[i]);
26912712 av_freep(&avctx->internal->pool);
2713+
2714+ if (avctx->hwaccel && avctx->hwaccel->uninit)
2715+ avctx->hwaccel->uninit(avctx);
2716+ av_freep(&avctx->internal->hwaccel_priv_data);
2717+
26922718 av_freep(&avctx->internal);
26932719 }
26942720

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t