1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavc: replace AVCodecContext.encode with subtitle-specific callback

AVCodecContext.encode is currently used only for subtitles, encode2 is
used for audio and video.
This commit is contained in:
Anton Khirnov 2012-08-18 16:41:24 +02:00
parent 9f64c8219a
commit 466b39efaf
6 changed files with 18 additions and 16 deletions

View File

@ -37,9 +37,9 @@ static av_cold int ass_encode_init(AVCodecContext *avctx)
} }
static int ass_encode_frame(AVCodecContext *avctx, static int ass_encode_frame(AVCodecContext *avctx,
unsigned char *buf, int bufsize, void *data) unsigned char *buf, int bufsize,
const AVSubtitle *sub)
{ {
AVSubtitle *sub = data;
int i, len, total_len = 0; int i, len, total_len = 0;
for (i=0; i<sub->num_rects; i++) { for (i=0; i<sub->num_rects; i++) {
@ -67,5 +67,5 @@ AVCodec ff_ass_encoder = {
.type = AVMEDIA_TYPE_SUBTITLE, .type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_SSA, .id = AV_CODEC_ID_SSA,
.init = ass_encode_init, .init = ass_encode_init,
.encode = ass_encode_frame, .encode_sub = ass_encode_frame,
}; };

View File

@ -2901,6 +2901,8 @@ typedef struct AVProfile {
typedef struct AVCodecDefault AVCodecDefault; typedef struct AVCodecDefault AVCodecDefault;
struct AVSubtitle;
/** /**
* AVCodec. * AVCodec.
*/ */
@ -2973,7 +2975,8 @@ typedef struct AVCodec {
void (*init_static_data)(struct AVCodec *codec); void (*init_static_data)(struct AVCodec *codec);
int (*init)(AVCodecContext *); int (*init)(AVCodecContext *);
int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
const struct AVSubtitle *sub);
/** /**
* Encode data to an AVPacket. * Encode data to an AVPacket.
* *

View File

@ -195,7 +195,7 @@ static void dvb_encode_rle4(uint8_t **pq,
} }
static int encode_dvb_subtitles(DVBSubtitleContext *s, static int encode_dvb_subtitles(DVBSubtitleContext *s,
uint8_t *outbuf, AVSubtitle *h) uint8_t *outbuf, const AVSubtitle *h)
{ {
uint8_t *q, *pseg_len; uint8_t *q, *pseg_len;
int page_id, region_id, clut_id, object_id, i, bpp_index, page_state; int page_id, region_id, clut_id, object_id, i, bpp_index, page_state;
@ -392,10 +392,10 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s,
} }
static int dvbsub_encode(AVCodecContext *avctx, static int dvbsub_encode(AVCodecContext *avctx,
unsigned char *buf, int buf_size, void *data) unsigned char *buf, int buf_size,
const AVSubtitle *sub)
{ {
DVBSubtitleContext *s = avctx->priv_data; DVBSubtitleContext *s = avctx->priv_data;
AVSubtitle *sub = data;
int ret; int ret;
ret = encode_dvb_subtitles(s, buf, sub); ret = encode_dvb_subtitles(s, buf, sub);
@ -407,6 +407,6 @@ AVCodec ff_dvbsub_encoder = {
.type = AVMEDIA_TYPE_SUBTITLE, .type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_DVB_SUBTITLE, .id = AV_CODEC_ID_DVB_SUBTITLE,
.priv_data_size = sizeof(DVBSubtitleContext), .priv_data_size = sizeof(DVBSubtitleContext),
.encode = dvbsub_encode, .encode_sub = dvbsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"), .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
}; };

View File

@ -205,10 +205,10 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size,
} }
static int dvdsub_encode(AVCodecContext *avctx, static int dvdsub_encode(AVCodecContext *avctx,
unsigned char *buf, int buf_size, void *data) unsigned char *buf, int buf_size,
const AVSubtitle *sub)
{ {
//DVDSubtitleContext *s = avctx->priv_data; //DVDSubtitleContext *s = avctx->priv_data;
AVSubtitle *sub = data;
int ret; int ret;
ret = encode_dvd_subtitles(buf, buf_size, sub); ret = encode_dvd_subtitles(buf, buf_size, sub);
@ -219,6 +219,6 @@ AVCodec ff_dvdsub_encoder = {
.name = "dvdsub", .name = "dvdsub",
.type = AVMEDIA_TYPE_SUBTITLE, .type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_DVD_SUBTITLE, .id = AV_CODEC_ID_DVD_SUBTITLE,
.encode = dvdsub_encode, .encode_sub = dvdsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"), .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"),
}; };

View File

@ -115,7 +115,7 @@ static void avcodec_init(void)
int av_codec_is_encoder(const AVCodec *codec) int av_codec_is_encoder(const AVCodec *codec)
{ {
return codec && (codec->encode || codec->encode2); return codec && (codec->encode_sub || codec->encode2);
} }
int av_codec_is_decoder(const AVCodec *codec) int av_codec_is_decoder(const AVCodec *codec)
@ -1174,7 +1174,7 @@ int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
} }
if(sub->num_rects == 0 || !sub->rects) if(sub->num_rects == 0 || !sub->rects)
return -1; return -1;
ret = avctx->codec->encode(avctx, buf, buf_size, sub); ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
avctx->frame_number++; avctx->frame_number++;
return ret; return ret;
} }

View File

@ -111,9 +111,8 @@ static int make_tc(uint64_t ms, int *tc)
} }
static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, static int xsub_encode(AVCodecContext *avctx, unsigned char *buf,
int bufsize, void *data) int bufsize, const AVSubtitle *h)
{ {
AVSubtitle *h = data;
uint64_t startTime = h->pts / 1000; // FIXME: need better solution... uint64_t startTime = h->pts / 1000; // FIXME: need better solution...
uint64_t endTime = startTime + h->end_display_time - h->start_display_time; uint64_t endTime = startTime + h->end_display_time - h->start_display_time;
int start_tc[4], end_tc[4]; int start_tc[4], end_tc[4];
@ -215,6 +214,6 @@ AVCodec ff_xsub_encoder = {
.type = AVMEDIA_TYPE_SUBTITLE, .type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_XSUB, .id = AV_CODEC_ID_XSUB,
.init = xsub_encoder_init, .init = xsub_encoder_init,
.encode = xsub_encode, .encode_sub= xsub_encode,
.long_name = NULL_IF_CONFIG_SMALL("DivX subtitles (XSUB)"), .long_name = NULL_IF_CONFIG_SMALL("DivX subtitles (XSUB)"),
}; };