Commit b5d714f4 authored by Philip Langdale's avatar Philip Langdale

crystalhd: Switch to new decode API and remove the insanity

The new decode API allows for m:n decode patterns, which is what
you need to use this hardware in a sane way. There are so many
situations where 1:1 doesn't happen naturally that it's a miracle
I got it working as well as I did.

With this change, we can throw all of the crazy heuristics and
sleeps(!) out, and things work correctly.
parent 234d3cbf
...@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release, ...@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest. releases are sorted from youngest to oldest.
version <next>: version <next>:
- CrystalHD decoder moved to new decode API
version 3.2: version 3.2:
- libopenmpt demuxer - libopenmpt demuxer
......
...@@ -97,10 +97,6 @@ ...@@ -97,10 +97,6 @@
#define OUTPUT_PROC_TIMEOUT 50 #define OUTPUT_PROC_TIMEOUT 50
/** Step between fake timestamps passed to hardware in units of 100ns */ /** Step between fake timestamps passed to hardware in units of 100ns */
#define TIMESTAMP_UNIT 100000 #define TIMESTAMP_UNIT 100000
/** Initial value in us of the wait in decode() */
#define BASE_WAIT 10000
/** Increment in us to adjust wait in decode() */
#define WAIT_UNIT 1000
/***************************************************************************** /*****************************************************************************
...@@ -110,9 +106,6 @@ ...@@ -110,9 +106,6 @@
typedef enum { typedef enum {
RET_ERROR = -1, RET_ERROR = -1,
RET_OK = 0, RET_OK = 0,
RET_COPY_AGAIN = 1,
RET_SKIP_NEXT_COPY = 2,
RET_COPY_NEXT_FIELD = 3,
} CopyRet; } CopyRet;
typedef struct OpaqueList { typedef struct OpaqueList {
...@@ -138,10 +131,7 @@ typedef struct { ...@@ -138,10 +131,7 @@ typedef struct {
uint8_t *sps_pps_buf; uint8_t *sps_pps_buf;
uint32_t sps_pps_size; uint32_t sps_pps_size;
uint8_t is_nal; uint8_t is_nal;
uint8_t output_ready;
uint8_t need_second_field; uint8_t need_second_field;
uint8_t skip_next_output;
uint64_t decode_wait;
uint64_t last_picture; uint64_t last_picture;
...@@ -188,42 +178,42 @@ static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum AVCodecID id) ...@@ -188,42 +178,42 @@ static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum AVCodecID id)
static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output) static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output)
{ {
av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz); av_log(priv->avctx, AV_LOG_TRACE, "\tYBuffSz: %u\n", output->YbuffSz);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tYBuffDoneSz: %u\n",
output->YBuffDoneSz); output->YBuffDoneSz);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tUVBuffDoneSz: %u\n",
output->UVBuffDoneSz); output->UVBuffDoneSz);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n", av_log(priv->avctx, AV_LOG_TRACE, "\tTimestamp: %"PRIu64"\n",
output->PicInfo.timeStamp); output->PicInfo.timeStamp);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tPicture Number: %u\n",
output->PicInfo.picture_number); output->PicInfo.picture_number);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tWidth: %u\n",
output->PicInfo.width); output->PicInfo.width);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tHeight: %u\n",
output->PicInfo.height); output->PicInfo.height);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n", av_log(priv->avctx, AV_LOG_TRACE, "\tChroma: 0x%03x\n",
output->PicInfo.chroma_format); output->PicInfo.chroma_format);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tPulldown: %u\n",
output->PicInfo.pulldown); output->PicInfo.pulldown);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n", av_log(priv->avctx, AV_LOG_TRACE, "\tFlags: 0x%08x\n",
output->PicInfo.flags); output->PicInfo.flags);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tFrame Rate/Res: %u\n",
output->PicInfo.frame_rate); output->PicInfo.frame_rate);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tAspect Ratio: %u\n",
output->PicInfo.aspect_ratio); output->PicInfo.aspect_ratio);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tColor Primaries: %u\n",
output->PicInfo.colour_primaries); output->PicInfo.colour_primaries);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tMetaData: %u\n",
output->PicInfo.picture_meta_payload); output->PicInfo.picture_meta_payload);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tSession Number: %u\n",
output->PicInfo.sess_num); output->PicInfo.sess_num);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tycom: %u\n",
output->PicInfo.ycom); output->PicInfo.ycom);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tCustom Aspect: %u\n",
output->PicInfo.custom_aspect_ratio_width_height); output->PicInfo.custom_aspect_ratio_width_height);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n", av_log(priv->avctx, AV_LOG_TRACE, "\tFrames to Drop: %u\n",
output->PicInfo.n_drop); output->PicInfo.n_drop);
av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n", av_log(priv->avctx, AV_LOG_TRACE, "\tH264 Valid Fields: 0x%08x\n",
output->PicInfo.other.h264.valid); output->PicInfo.other.h264.valid);
} }
...@@ -319,12 +309,8 @@ static void flush(AVCodecContext *avctx) ...@@ -319,12 +309,8 @@ static void flush(AVCodecContext *avctx)
{ {
CHDContext *priv = avctx->priv_data; CHDContext *priv = avctx->priv_data;
avctx->has_b_frames = 0;
priv->last_picture = -1; priv->last_picture = -1;
priv->output_ready = 0;
priv->need_second_field = 0; priv->need_second_field = 0;
priv->skip_next_output = 0;
priv->decode_wait = BASE_WAIT;
av_frame_unref (priv->pic); av_frame_unref (priv->pic);
...@@ -460,7 +446,6 @@ static av_cold int init(AVCodecContext *avctx) ...@@ -460,7 +446,6 @@ static av_cold int init(AVCodecContext *avctx)
priv->avctx = avctx; priv->avctx = avctx;
priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1; priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1;
priv->last_picture = -1; priv->last_picture = -1;
priv->decode_wait = BASE_WAIT;
priv->pic = av_frame_alloc(); priv->pic = av_frame_alloc();
subtype = id2subtype(priv, avctx->codec->id); subtype = id2subtype(priv, avctx->codec->id);
...@@ -759,35 +744,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -759,35 +744,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
} }
} }
/* return RET_OK;
* Two types of PAFF content have been observed. One form causes the
* hardware to return a field pair and the other individual fields,
* even though the input is always individual fields. We must skip
* copying on the next decode() call to maintain pipeline length in
* the first case.
*/
if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
(pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
return RET_SKIP_NEXT_COPY;
}
/*
* The logic here is purely based on empirical testing with samples.
* If we need a second field, it could come from a second input packet,
* or it could come from the same field-pair input packet at the current
* field. In the first case, we should return and wait for the next time
* round to get the second field, while in the second case, we should
* ask the decoder for it immediately.
*
* Testing has shown that we are dealing with the fieldpair -> two fields
* case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture
* type was PICT_FRAME (in this second case, the flag might still be set)
*/
return priv->need_second_field &&
(!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
pic_type == PICT_FRAME) ?
RET_COPY_NEXT_FIELD : RET_OK;
} }
...@@ -860,7 +817,7 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, ...@@ -860,7 +817,7 @@ static inline CopyRet receive_frame(AVCodecContext *avctx,
avctx->sample_aspect_ratio = (AVRational) {221, 1}; avctx->sample_aspect_ratio = (AVRational) {221, 1};
break; break;
} }
return RET_COPY_AGAIN; return RET_OK;
} else if (ret == BC_STS_SUCCESS) { } else if (ret == BC_STS_SUCCESS) {
int copy_ret = -1; int copy_ret = -1;
if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) { if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
...@@ -878,24 +835,16 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, ...@@ -878,24 +835,16 @@ static inline CopyRet receive_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
"CrystalHD: Picture Number discontinuity\n"); "CrystalHD: Picture Number discontinuity\n");
/* /*
* Have we lost frames? If so, we need to shrink the
* pipeline length appropriately.
*
* XXX: I have no idea what the semantics of this situation * XXX: I have no idea what the semantics of this situation
* are so I don't even know if we've lost frames or which * are so I don't even know if we've lost frames or which
* ones. * ones.
*
* In any case, only warn the first time.
*/ */
priv->last_picture = output.PicInfo.picture_number - 1; priv->last_picture = output.PicInfo.picture_number - 1;
} }
copy_ret = copy_frame(avctx, &output, data, got_frame); copy_ret = copy_frame(avctx, &output, data, got_frame);
if (*got_frame > 0) { if (*got_frame > 0) {
avctx->has_b_frames--;
priv->last_picture++; priv->last_picture++;
av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
avctx->has_b_frames);
} }
} else { } else {
/* /*
...@@ -903,108 +852,88 @@ static inline CopyRet receive_frame(AVCodecContext *avctx, ...@@ -903,108 +852,88 @@ static inline CopyRet receive_frame(AVCodecContext *avctx,
*/ */
av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with " av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
"invalid PIB\n"); "invalid PIB\n");
avctx->has_b_frames--;
copy_ret = RET_OK; copy_ret = RET_OK;
} }
DtsReleaseOutputBuffs(dev, NULL, FALSE); DtsReleaseOutputBuffs(dev, NULL, FALSE);
return copy_ret; return copy_ret;
} else if (ret == BC_STS_BUSY) { } else if (ret == BC_STS_BUSY) {
return RET_COPY_AGAIN; return RET_OK;
} else { } else {
av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret); av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
return RET_ERROR; return RET_ERROR;
} }
} }
static int crystalhd_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
{ {
BC_STATUS ret; BC_STATUS bc_ret;
BC_DTS_STATUS decoder_status = { 0, };
CopyRet rec_ret;
CHDContext *priv = avctx->priv_data; CHDContext *priv = avctx->priv_data;
HANDLE dev = priv->dev; HANDLE dev = priv->dev;
uint8_t *in_data = avpkt->data;
int len = avpkt->size;
int free_data = 0;
uint8_t pic_type = 0; uint8_t pic_type = 0;
AVPacket filtered_packet = { 0 };
int ret = 0;
av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n"); av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_packet\n");
if (len) { if (avpkt && avpkt->size) {
int32_t tx_free = (int32_t)DtsTxFreeSize(dev); int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
if (priv->bsfc) { if (priv->bsfc) {
int ret = 0;
AVPacket filter_packet = { 0 }; AVPacket filter_packet = { 0 };
AVPacket filtered_packet = { 0 };
ret = av_packet_ref(&filter_packet, avpkt); ret = av_packet_ref(&filter_packet, avpkt);
if (ret < 0) { if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter "
"failed to ref input packet\n"); "failed to ref input packet\n");
return ret; goto exit;
} }
ret = av_bsf_send_packet(priv->bsfc, &filter_packet); ret = av_bsf_send_packet(priv->bsfc, &filter_packet);
if (ret < 0) { if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter "
"failed to send input packet\n"); "failed to send input packet\n");
return ret; goto exit;
} }
ret = av_bsf_receive_packet(priv->bsfc, &filtered_packet); ret = av_bsf_receive_packet(priv->bsfc, &filtered_packet);
if (ret < 0) { if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter " av_log(avctx, AV_LOG_ERROR, "CrystalHD: mpv4toannexb filter "
"failed to receive output packet\n"); "failed to receive output packet\n");
return ret; goto exit;
} }
in_data = filtered_packet.data; avpkt = &filtered_packet;
len = filtered_packet.size;
av_packet_unref(&filter_packet); av_packet_unref(&filter_packet);
} }
if (priv->parser) { if (priv->parser) {
int ret = 0; uint8_t *pout;
int psize;
free_data = ret > 0; int index;
H264Context *h = priv->parser->priv_data;
if (ret >= 0) {
uint8_t *pout; index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
int psize; avpkt->data, avpkt->size, avpkt->pts,
int index; avpkt->dts, 0);
H264Context *h = priv->parser->priv_data; if (index < 0) {
index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
in_data, len, avpkt->pts,
avpkt->dts, 0);
if (index < 0) {
av_log(avctx, AV_LOG_WARNING,
"CrystalHD: Failed to parse h.264 packet to "
"detect interlacing.\n");
} else if (index != len) {
av_log(avctx, AV_LOG_WARNING,
"CrystalHD: Failed to parse h.264 packet "
"completely. Interlaced frames may be "
"incorrectly detected.\n");
} else {
av_log(avctx, AV_LOG_VERBOSE,
"CrystalHD: parser picture type %d\n",
h->picture_structure);
pic_type = h->picture_structure;
}
} else {
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
"CrystalHD: mp4toannexb filter failed to filter " "CrystalHD: Failed to parse h.264 packet to "
"packet. Interlaced frames may be incorrectly " "detect interlacing.\n");
"detected.\n"); } else if (index != avpkt->size) {
av_log(avctx, AV_LOG_WARNING,
"CrystalHD: Failed to parse h.264 packet "
"completely. Interlaced frames may be "
"incorrectly detected.\n");
} else {
av_log(avctx, AV_LOG_VERBOSE,
"CrystalHD: parser picture type %d\n",
h->picture_structure);
pic_type = h->picture_structure;
} }
} }
if (len < tx_free - 1024) { if (avpkt->size < tx_free) {
/* /*
* Despite being notionally opaque, either libcrystalhd or * Despite being notionally opaque, either libcrystalhd or
* the hardware itself will mangle pts values that are too * the hardware itself will mangle pts values that are too
...@@ -1017,272 +946,113 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a ...@@ -1017,272 +946,113 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a
int64_t safe_pts = avpkt->pts == AV_NOPTS_VALUE ? 0 : avpkt->pts; int64_t safe_pts = avpkt->pts == AV_NOPTS_VALUE ? 0 : avpkt->pts;
uint64_t pts = opaque_list_push(priv, safe_pts, pic_type); uint64_t pts = opaque_list_push(priv, safe_pts, pic_type);
if (!pts) { if (!pts) {
if (free_data) { ret = AVERROR(ENOMEM);
av_freep(&in_data); goto exit;
}
return AVERROR(ENOMEM);
} }
av_log(priv->avctx, AV_LOG_VERBOSE, av_log(priv->avctx, AV_LOG_VERBOSE,
"input \"pts\": %"PRIu64"\n", pts); "input \"pts\": %"PRIu64"\n", pts);
ret = DtsProcInput(dev, in_data, len, pts, 0); bc_ret = DtsProcInput(dev, avpkt->data, avpkt->size, pts, 0);
if (free_data) { if (bc_ret == BC_STS_BUSY) {
av_freep(&in_data);
}
if (ret == BC_STS_BUSY) {
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
"CrystalHD: ProcInput returned busy\n"); "CrystalHD: ProcInput returned busy\n");
usleep(BASE_WAIT); ret = AVERROR(EAGAIN);
return AVERROR(EBUSY); goto exit;
} else if (ret != BC_STS_SUCCESS) { } else if (bc_ret != BC_STS_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"CrystalHD: ProcInput failed: %u\n", ret); "CrystalHD: ProcInput failed: %u\n", ret);
return -1; ret = -1;
goto exit;
} }
avctx->has_b_frames++;
} else { } else {
av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n"); av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Input buffer full\n");
len = 0; // We didn't consume any bytes. ret = AVERROR(EAGAIN);
goto exit;
} }
} else { } else {
av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n"); av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
ret = AVERROR_EOF;
goto exit;
} }
exit:
av_packet_unref(&filtered_packet);
return ret;
}
if (priv->skip_next_output) { static int crystalhd_receive_frame(AVCodecContext *avctx, AVFrame *frame)
av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n"); {
priv->skip_next_output = 0; BC_STATUS bc_ret;
avctx->has_b_frames--; BC_DTS_STATUS decoder_status = { 0, };
return len; CopyRet rec_ret;
} CHDContext *priv = avctx->priv_data;
HANDLE dev = priv->dev;
int got_frame = 0;
ret = DtsGetDriverStatus(dev, &decoder_status); av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: receive_frame\n");
if (ret != BC_STS_SUCCESS) {
bc_ret = DtsGetDriverStatus(dev, &decoder_status);
if (bc_ret != BC_STS_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n"); av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
return -1; return -1;
} }
/* if (decoder_status.ReadyListCount == 0) {
* No frames ready. Don't try to extract. av_log(avctx, AV_LOG_INFO, "CrystalHD: Insufficient frames ready. Returning\n");
* return AVERROR(EAGAIN);
* Empirical testing shows that ReadyListCount can be a damn lie,
* and ProcOut still fails when count > 0. The same testing showed
* that two more iterations were needed before ProcOutput would
* succeed.
*/
if (priv->output_ready < 2) {
if (decoder_status.ReadyListCount != 0)
priv->output_ready++;
usleep(BASE_WAIT);
av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
return len;
} else if (decoder_status.ReadyListCount == 0) {
/*
* After the pipeline is established, if we encounter a lack of frames
* that probably means we're not giving the hardware enough time to
* decode them, so start increasing the wait time at the end of a
* decode call.
*/
usleep(BASE_WAIT);
priv->decode_wait += WAIT_UNIT;
av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
return len;
} }
do { rec_ret = receive_frame(avctx, frame, &got_frame);
rec_ret = receive_frame(avctx, data, got_frame); if (rec_ret == RET_ERROR) {
if (rec_ret == RET_OK && *got_frame == 0) { return -1;
/* } else if (got_frame == 0) {
* This case is for when the encoded fields are stored return AVERROR(EAGAIN);
* separately and we get a separate avpkt for each one. To keep } else {
* the pipeline stable, we should return nothing and wait for return 0;
* the next time round to grab the second field. }
* H.264 PAFF is an example of this.
*/
av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
avctx->has_b_frames--;
} else if (rec_ret == RET_COPY_NEXT_FIELD) {
/*
* This case is for when the encoded fields are stored in a
* single avpkt but the hardware returns then separately. Unless
* we grab the second field before returning, we'll slip another
* frame in the pipeline and if that happens a lot, we're sunk.
* So we have to get that second field now.
* Interlaced mpeg2 and vc1 are examples of this.
*/
av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
while (1) {
usleep(priv->decode_wait);
ret = DtsGetDriverStatus(dev, &decoder_status);
if (ret == BC_STS_SUCCESS &&
decoder_status.ReadyListCount > 0) {
rec_ret = receive_frame(avctx, data, got_frame);
if ((rec_ret == RET_OK && *got_frame > 0) ||
rec_ret == RET_ERROR)
break;
}
}
av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
} else if (rec_ret == RET_SKIP_NEXT_COPY) {
/*
* Two input packets got turned into a field pair. Gawd.
*/
av_log(avctx, AV_LOG_VERBOSE,
"Don't output on next decode call.\n");
priv->skip_next_output = 1;
}
/*
* If rec_ret == RET_COPY_AGAIN, that means that either we just handled
* a FMT_CHANGE event and need to go around again for the actual frame,
* we got a busy status and need to try again, or we're dealing with
* packed b-frames, where the hardware strangely returns the packed
* p-frame twice. We choose to keep the second copy as it carries the
* valid pts.
*/
} while (rec_ret == RET_COPY_AGAIN);
usleep(priv->decode_wait);
return len;
} }
#define DEFINE_CRYSTALHD_DECODER(x, X) \
static const AVClass x##_crystalhd_class = { \
.class_name = #x "_crystalhd", \
.item_name = av_default_item_name, \
.option = options, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
AVCodec ff_##x##_crystalhd_decoder = { \
.name = #x "_crystalhd", \
.long_name = NULL_IF_CONFIG_SMALL("CrystalHD " #X " decoder"), \
.type = AVMEDIA_TYPE_VIDEO, \
.id = AV_CODEC_ID_##X, \
.priv_data_size = sizeof(CHDContext), \
.priv_class = &x##_crystalhd_class, \
.init = init, \
.close = uninit, \
.send_packet = crystalhd_decode_packet, \
.receive_frame = crystalhd_receive_frame, \
.flush = flush, \
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, \
};
#if CONFIG_H264_CRYSTALHD_DECODER #if CONFIG_H264_CRYSTALHD_DECODER
static AVClass h264_class = { DEFINE_CRYSTALHD_DECODER(h264, H264)
"h264_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_h264_crystalhd_decoder = {
.name = "h264_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H264,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &h264_class,
};
#endif #endif
#if CONFIG_MPEG2_CRYSTALHD_DECODER #if CONFIG_MPEG2_CRYSTALHD_DECODER
static AVClass mpeg2_class = { DEFINE_CRYSTALHD_DECODER(mpeg2, MPEG2VIDEO)
"mpeg2_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_mpeg2_crystalhd_decoder = {
.name = "mpeg2_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG2VIDEO,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &mpeg2_class,
};
#endif #endif
#if CONFIG_MPEG4_CRYSTALHD_DECODER #if CONFIG_MPEG4_CRYSTALHD_DECODER
static AVClass mpeg4_class = { DEFINE_CRYSTALHD_DECODER(mpeg4, MPEG4)
"mpeg4_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_mpeg4_crystalhd_decoder = {
.name = "mpeg4_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG4,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &mpeg4_class,
};
#endif #endif
#if CONFIG_MSMPEG4_CRYSTALHD_DECODER #if CONFIG_MSMPEG4_CRYSTALHD_DECODER
static AVClass msmpeg4_class = { DEFINE_CRYSTALHD_DECODER(msmpeg4, MSMPEG4V3)
"msmpeg4_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_msmpeg4_crystalhd_decoder = {
.name = "msmpeg4_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MSMPEG4V3,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &msmpeg4_class,
};
#endif #endif
#if CONFIG_VC1_CRYSTALHD_DECODER #if CONFIG_VC1_CRYSTALHD_DECODER
static AVClass vc1_class = { DEFINE_CRYSTALHD_DECODER(vc1, VC1)
"vc1_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_vc1_crystalhd_decoder = {
.name = "vc1_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VC1,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &vc1_class,
};
#endif #endif
#if CONFIG_WMV3_CRYSTALHD_DECODER #if CONFIG_WMV3_CRYSTALHD_DECODER
static AVClass wmv3_class = { DEFINE_CRYSTALHD_DECODER(wmv3, WMV3)
"wmv3_crystalhd",
av_default_item_name,
options,
LIBAVUTIL_VERSION_INT,
};
AVCodec ff_wmv3_crystalhd_decoder = {
.name = "wmv3_crystalhd",
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV3,
.priv_data_size = sizeof(CHDContext),
.init = init,
.close = uninit,
.decode = decode,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.flush = flush,
.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
.priv_class = &wmv3_class,
};
#endif #endif
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 65 #define LIBAVCODEC_VERSION_MINOR 66
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment