yading@10: /* yading@10: * - CrystalHD decoder module - yading@10: * yading@10: * Copyright(C) 2010,2011 Philip Langdale yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /* yading@10: * - Principles of Operation - yading@10: * yading@10: * The CrystalHD decoder operates at the bitstream level - which is an even yading@10: * higher level than the decoding hardware you typically see in modern GPUs. yading@10: * This means it has a very simple interface, in principle. You feed demuxed yading@10: * packets in one end and get decoded picture (fields/frames) out the other. yading@10: * yading@10: * Of course, nothing is ever that simple. Due, at the very least, to b-frame yading@10: * dependencies in the supported formats, the hardware has a delay between yading@10: * when a packet goes in, and when a picture comes out. Furthermore, this delay yading@10: * is not just a function of time, but also one of the dependency on additional yading@10: * frames being fed into the decoder to satisfy the b-frame dependencies. yading@10: * yading@10: * As such, a pipeline will build up that is roughly equivalent to the required yading@10: * DPB for the file being played. If that was all it took, things would still yading@10: * be simple - so, of course, it isn't. yading@10: * yading@10: * The hardware has a way of indicating that a picture is ready to be copied out, yading@10: * but this is unreliable - and sometimes the attempt will still fail so, based yading@10: * on testing, the code will wait until 3 pictures are ready before starting yading@10: * to copy out - and this has the effect of extending the pipeline. yading@10: * yading@10: * Finally, while it is tempting to say that once the decoder starts outputting yading@10: * frames, the software should never fail to return a frame from a decode(), yading@10: * this is a hard assertion to make, because the stream may switch between yading@10: * differently encoded content (number of b-frames, interlacing, etc) which yading@10: * might require a longer pipeline than before. If that happened, you could yading@10: * deadlock trying to retrieve a frame that can't be decoded without feeding yading@10: * in additional packets. yading@10: * yading@10: * As such, the code will return in the event that a picture cannot be copied yading@10: * out, leading to an increase in the length of the pipeline. This in turn, yading@10: * means we have to be sensitive to the time it takes to decode a picture; yading@10: * We do not want to give up just because the hardware needed a little more yading@10: * time to prepare the picture! For this reason, there are delays included yading@10: * in the decode() path that ensure that, under normal conditions, the hardware yading@10: * will only fail to return a frame if it really needs additional packets to yading@10: * complete the decoding. yading@10: * yading@10: * Finally, to be explicit, we do not want the pipeline to grow without bound yading@10: * for two reasons: 1) The hardware can only buffer a finite number of packets, yading@10: * and 2) The client application may not be able to cope with arbitrarily long yading@10: * delays in the video path relative to the audio path. For example. MPlayer yading@10: * can only handle a 20 picture delay (although this is arbitrary, and needs yading@10: * to be extended to fully support the CrystalHD where the delay could be up yading@10: * to 32 pictures - consider PAFF H.264 content with 16 b-frames). yading@10: */ yading@10: yading@10: /***************************************************************************** yading@10: * Includes yading@10: ****************************************************************************/ yading@10: yading@10: #define _XOPEN_SOURCE 600 yading@10: #include yading@10: #include yading@10: #include yading@10: #include yading@10: yading@10: #include yading@10: #include yading@10: #include yading@10: yading@10: #include "avcodec.h" yading@10: #include "h264.h" yading@10: #include "internal.h" yading@10: #include "libavutil/imgutils.h" yading@10: #include "libavutil/intreadwrite.h" yading@10: #include "libavutil/opt.h" yading@10: yading@10: /** Timeout parameter passed to DtsProcOutput() in us */ yading@10: #define OUTPUT_PROC_TIMEOUT 50 yading@10: /** Step between fake timestamps passed to hardware in units of 100ns */ yading@10: #define TIMESTAMP_UNIT 100000 yading@10: /** Initial value in us of the wait in decode() */ yading@10: #define BASE_WAIT 10000 yading@10: /** Increment in us to adjust wait in decode() */ yading@10: #define WAIT_UNIT 1000 yading@10: yading@10: yading@10: /***************************************************************************** yading@10: * Module private data yading@10: ****************************************************************************/ yading@10: yading@10: typedef enum { yading@10: RET_ERROR = -1, yading@10: RET_OK = 0, yading@10: RET_COPY_AGAIN = 1, yading@10: RET_SKIP_NEXT_COPY = 2, yading@10: RET_COPY_NEXT_FIELD = 3, yading@10: } CopyRet; yading@10: yading@10: typedef struct OpaqueList { yading@10: struct OpaqueList *next; yading@10: uint64_t fake_timestamp; yading@10: uint64_t reordered_opaque; yading@10: uint8_t pic_type; yading@10: } OpaqueList; yading@10: yading@10: typedef struct { yading@10: AVClass *av_class; yading@10: AVCodecContext *avctx; yading@10: AVFrame *pic; yading@10: HANDLE dev; yading@10: yading@10: uint8_t *orig_extradata; yading@10: uint32_t orig_extradata_size; yading@10: yading@10: AVBitStreamFilterContext *bsfc; yading@10: AVCodecParserContext *parser; yading@10: yading@10: uint8_t is_70012; yading@10: uint8_t *sps_pps_buf; yading@10: uint32_t sps_pps_size; yading@10: uint8_t is_nal; yading@10: uint8_t output_ready; yading@10: uint8_t need_second_field; yading@10: uint8_t skip_next_output; yading@10: uint64_t decode_wait; yading@10: yading@10: uint64_t last_picture; yading@10: yading@10: OpaqueList *head; yading@10: OpaqueList *tail; yading@10: yading@10: /* Options */ yading@10: uint32_t sWidth; yading@10: uint8_t bframe_bug; yading@10: } CHDContext; yading@10: yading@10: static const AVOption options[] = { yading@10: { "crystalhd_downscale_width", yading@10: "Turn on downscaling to the specified width", yading@10: offsetof(CHDContext, sWidth), yading@10: AV_OPT_TYPE_INT, {.i64 = 0}, 0, UINT32_MAX, yading@10: AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, }, yading@10: { NULL, }, yading@10: }; yading@10: yading@10: yading@10: /***************************************************************************** yading@10: * Helper functions yading@10: ****************************************************************************/ yading@10: yading@10: static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum AVCodecID id) yading@10: { yading@10: switch (id) { yading@10: case AV_CODEC_ID_MPEG4: yading@10: return BC_MSUBTYPE_DIVX; yading@10: case AV_CODEC_ID_MSMPEG4V3: yading@10: return BC_MSUBTYPE_DIVX311; yading@10: case AV_CODEC_ID_MPEG2VIDEO: yading@10: return BC_MSUBTYPE_MPEG2VIDEO; yading@10: case AV_CODEC_ID_VC1: yading@10: return BC_MSUBTYPE_VC1; yading@10: case AV_CODEC_ID_WMV3: yading@10: return BC_MSUBTYPE_WMV3; yading@10: case AV_CODEC_ID_H264: yading@10: return priv->is_nal ? BC_MSUBTYPE_AVC1 : BC_MSUBTYPE_H264; yading@10: default: yading@10: return BC_MSUBTYPE_INVALID; yading@10: } yading@10: } yading@10: yading@10: static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output) yading@10: { yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n", yading@10: output->YBuffDoneSz); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n", yading@10: output->UVBuffDoneSz); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n", yading@10: output->PicInfo.timeStamp); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n", yading@10: output->PicInfo.picture_number); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n", yading@10: output->PicInfo.width); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n", yading@10: output->PicInfo.height); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n", yading@10: output->PicInfo.chroma_format); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n", yading@10: output->PicInfo.pulldown); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n", yading@10: output->PicInfo.flags); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n", yading@10: output->PicInfo.frame_rate); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n", yading@10: output->PicInfo.aspect_ratio); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n", yading@10: output->PicInfo.colour_primaries); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n", yading@10: output->PicInfo.picture_meta_payload); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n", yading@10: output->PicInfo.sess_num); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n", yading@10: output->PicInfo.ycom); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n", yading@10: output->PicInfo.custom_aspect_ratio_width_height); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n", yading@10: output->PicInfo.n_drop); yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n", yading@10: output->PicInfo.other.h264.valid); yading@10: } yading@10: yading@10: yading@10: /***************************************************************************** yading@10: * OpaqueList functions yading@10: ****************************************************************************/ yading@10: yading@10: static uint64_t opaque_list_push(CHDContext *priv, uint64_t reordered_opaque, yading@10: uint8_t pic_type) yading@10: { yading@10: OpaqueList *newNode = av_mallocz(sizeof (OpaqueList)); yading@10: if (!newNode) { yading@10: av_log(priv->avctx, AV_LOG_ERROR, yading@10: "Unable to allocate new node in OpaqueList.\n"); yading@10: return 0; yading@10: } yading@10: if (!priv->head) { yading@10: newNode->fake_timestamp = TIMESTAMP_UNIT; yading@10: priv->head = newNode; yading@10: } else { yading@10: newNode->fake_timestamp = priv->tail->fake_timestamp + TIMESTAMP_UNIT; yading@10: priv->tail->next = newNode; yading@10: } yading@10: priv->tail = newNode; yading@10: newNode->reordered_opaque = reordered_opaque; yading@10: newNode->pic_type = pic_type; yading@10: yading@10: return newNode->fake_timestamp; yading@10: } yading@10: yading@10: /* yading@10: * The OpaqueList is built in decode order, while elements will be removed yading@10: * in presentation order. If frames are reordered, this means we must be yading@10: * able to remove elements that are not the first element. yading@10: * yading@10: * Returned node must be freed by caller. yading@10: */ yading@10: static OpaqueList *opaque_list_pop(CHDContext *priv, uint64_t fake_timestamp) yading@10: { yading@10: OpaqueList *node = priv->head; yading@10: yading@10: if (!priv->head) { yading@10: av_log(priv->avctx, AV_LOG_ERROR, yading@10: "CrystalHD: Attempted to query non-existent timestamps.\n"); yading@10: return NULL; yading@10: } yading@10: yading@10: /* yading@10: * The first element is special-cased because we have to manipulate yading@10: * the head pointer rather than the previous element in the list. yading@10: */ yading@10: if (priv->head->fake_timestamp == fake_timestamp) { yading@10: priv->head = node->next; yading@10: yading@10: if (!priv->head->next) yading@10: priv->tail = priv->head; yading@10: yading@10: node->next = NULL; yading@10: return node; yading@10: } yading@10: yading@10: /* yading@10: * The list is processed at arm's length so that we have the yading@10: * previous element available to rewrite its next pointer. yading@10: */ yading@10: while (node->next) { yading@10: OpaqueList *current = node->next; yading@10: if (current->fake_timestamp == fake_timestamp) { yading@10: node->next = current->next; yading@10: yading@10: if (!node->next) yading@10: priv->tail = node; yading@10: yading@10: current->next = NULL; yading@10: return current; yading@10: } else { yading@10: node = current; yading@10: } yading@10: } yading@10: yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, yading@10: "CrystalHD: Couldn't match fake_timestamp.\n"); yading@10: return NULL; yading@10: } yading@10: yading@10: yading@10: /***************************************************************************** yading@10: * Video decoder API function definitions yading@10: ****************************************************************************/ yading@10: yading@10: static void flush(AVCodecContext *avctx) yading@10: { yading@10: CHDContext *priv = avctx->priv_data; yading@10: yading@10: avctx->has_b_frames = 0; yading@10: priv->last_picture = -1; yading@10: priv->output_ready = 0; yading@10: priv->need_second_field = 0; yading@10: priv->skip_next_output = 0; yading@10: priv->decode_wait = BASE_WAIT; yading@10: yading@10: av_frame_unref (priv->pic); yading@10: yading@10: /* Flush mode 4 flushes all software and hardware buffers. */ yading@10: DtsFlushInput(priv->dev, 4); yading@10: } yading@10: yading@10: yading@10: static av_cold int uninit(AVCodecContext *avctx) yading@10: { yading@10: CHDContext *priv = avctx->priv_data; yading@10: HANDLE device; yading@10: yading@10: device = priv->dev; yading@10: DtsStopDecoder(device); yading@10: DtsCloseDecoder(device); yading@10: DtsDeviceClose(device); yading@10: yading@10: /* yading@10: * Restore original extradata, so that if the decoder is yading@10: * reinitialised, the bitstream detection and filtering yading@10: * will work as expected. yading@10: */ yading@10: if (priv->orig_extradata) { yading@10: av_free(avctx->extradata); yading@10: avctx->extradata = priv->orig_extradata; yading@10: avctx->extradata_size = priv->orig_extradata_size; yading@10: priv->orig_extradata = NULL; yading@10: priv->orig_extradata_size = 0; yading@10: } yading@10: yading@10: av_parser_close(priv->parser); yading@10: if (priv->bsfc) { yading@10: av_bitstream_filter_close(priv->bsfc); yading@10: } yading@10: yading@10: av_free(priv->sps_pps_buf); yading@10: yading@10: av_frame_free (&priv->pic); yading@10: yading@10: if (priv->head) { yading@10: OpaqueList *node = priv->head; yading@10: while (node) { yading@10: OpaqueList *next = node->next; yading@10: av_free(node); yading@10: node = next; yading@10: } yading@10: } yading@10: yading@10: return 0; yading@10: } yading@10: yading@10: yading@10: static av_cold int init(AVCodecContext *avctx) yading@10: { yading@10: CHDContext* priv; yading@10: BC_STATUS ret; yading@10: BC_INFO_CRYSTAL version; yading@10: BC_INPUT_FORMAT format = { yading@10: .FGTEnable = FALSE, yading@10: .Progressive = TRUE, yading@10: .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40, yading@10: .width = avctx->width, yading@10: .height = avctx->height, yading@10: }; yading@10: yading@10: BC_MEDIA_SUBTYPE subtype; yading@10: yading@10: uint32_t mode = DTS_PLAYBACK_MODE | yading@10: DTS_LOAD_FILE_PLAY_FW | yading@10: DTS_SKIP_TX_CHK_CPB | yading@10: DTS_PLAYBACK_DROP_RPT_MODE | yading@10: DTS_SINGLE_THREADED_MODE | yading@10: DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976); yading@10: yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n", yading@10: avctx->codec->name); yading@10: yading@10: avctx->pix_fmt = AV_PIX_FMT_YUYV422; yading@10: yading@10: /* Initialize the library */ yading@10: priv = avctx->priv_data; yading@10: priv->avctx = avctx; yading@10: priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1; yading@10: priv->last_picture = -1; yading@10: priv->decode_wait = BASE_WAIT; yading@10: priv->pic = av_frame_alloc(); yading@10: yading@10: subtype = id2subtype(priv, avctx->codec->id); yading@10: switch (subtype) { yading@10: case BC_MSUBTYPE_AVC1: yading@10: { yading@10: uint8_t *dummy_p; yading@10: int dummy_int; yading@10: yading@10: /* Back up the extradata so it can be restored at close time. */ yading@10: priv->orig_extradata = av_malloc(avctx->extradata_size); yading@10: if (!priv->orig_extradata) { yading@10: av_log(avctx, AV_LOG_ERROR, yading@10: "Failed to allocate copy of extradata\n"); yading@10: return AVERROR(ENOMEM); yading@10: } yading@10: priv->orig_extradata_size = avctx->extradata_size; yading@10: memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size); yading@10: yading@10: priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); yading@10: if (!priv->bsfc) { yading@10: av_log(avctx, AV_LOG_ERROR, yading@10: "Cannot open the h264_mp4toannexb BSF!\n"); yading@10: return AVERROR_BSF_NOT_FOUND; yading@10: } yading@10: av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p, yading@10: &dummy_int, NULL, 0, 0); yading@10: } yading@10: subtype = BC_MSUBTYPE_H264; yading@10: // Fall-through yading@10: case BC_MSUBTYPE_H264: yading@10: format.startCodeSz = 4; yading@10: // Fall-through yading@10: case BC_MSUBTYPE_VC1: yading@10: case BC_MSUBTYPE_WVC1: yading@10: case BC_MSUBTYPE_WMV3: yading@10: case BC_MSUBTYPE_WMVA: yading@10: case BC_MSUBTYPE_MPEG2VIDEO: yading@10: case BC_MSUBTYPE_DIVX: yading@10: case BC_MSUBTYPE_DIVX311: yading@10: format.pMetaData = avctx->extradata; yading@10: format.metaDataSz = avctx->extradata_size; yading@10: break; yading@10: default: yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: Unknown codec name\n"); yading@10: return AVERROR(EINVAL); yading@10: } yading@10: format.mSubtype = subtype; yading@10: yading@10: if (priv->sWidth) { yading@10: format.bEnableScaling = 1; yading@10: format.ScalingParams.sWidth = priv->sWidth; yading@10: } yading@10: yading@10: /* Get a decoder instance */ yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: starting up\n"); yading@10: // Initialize the Link and Decoder devices yading@10: ret = DtsDeviceOpen(&priv->dev, mode); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: DtsDeviceOpen failed\n"); yading@10: goto fail; yading@10: } yading@10: yading@10: ret = DtsCrystalHDVersion(priv->dev, &version); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "CrystalHD: DtsCrystalHDVersion failed\n"); yading@10: goto fail; yading@10: } yading@10: priv->is_70012 = version.device == 0; yading@10: yading@10: if (priv->is_70012 && yading@10: (subtype == BC_MSUBTYPE_DIVX || subtype == BC_MSUBTYPE_DIVX311)) { yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "CrystalHD: BCM70012 doesn't support MPEG4-ASP/DivX/Xvid\n"); yading@10: goto fail; yading@10: } yading@10: yading@10: ret = DtsSetInputFormat(priv->dev, &format); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: SetInputFormat failed\n"); yading@10: goto fail; yading@10: } yading@10: yading@10: ret = DtsOpenDecoder(priv->dev, BC_STREAM_TYPE_ES); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsOpenDecoder failed\n"); yading@10: goto fail; yading@10: } yading@10: yading@10: ret = DtsSetColorSpace(priv->dev, OUTPUT_MODE422_YUY2); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsSetColorSpace failed\n"); yading@10: goto fail; yading@10: } yading@10: ret = DtsStartDecoder(priv->dev); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartDecoder failed\n"); yading@10: goto fail; yading@10: } yading@10: ret = DtsStartCapture(priv->dev); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartCapture failed\n"); yading@10: goto fail; yading@10: } yading@10: yading@10: if (avctx->codec->id == AV_CODEC_ID_H264) { yading@10: priv->parser = av_parser_init(avctx->codec->id); yading@10: if (!priv->parser) yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "Cannot open the h.264 parser! Interlaced h.264 content " yading@10: "will not be detected reliably.\n"); yading@10: priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES; yading@10: } yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n"); yading@10: yading@10: return 0; yading@10: yading@10: fail: yading@10: uninit(avctx); yading@10: return -1; yading@10: } yading@10: yading@10: yading@10: static inline CopyRet copy_frame(AVCodecContext *avctx, yading@10: BC_DTS_PROC_OUT *output, yading@10: void *data, int *got_frame) yading@10: { yading@10: BC_STATUS ret; yading@10: BC_DTS_STATUS decoder_status = { 0, }; yading@10: uint8_t trust_interlaced; yading@10: uint8_t interlaced; yading@10: yading@10: CHDContext *priv = avctx->priv_data; yading@10: int64_t pkt_pts = AV_NOPTS_VALUE; yading@10: uint8_t pic_type = 0; yading@10: yading@10: uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) == yading@10: VDEC_FLAG_BOTTOMFIELD; yading@10: uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST); yading@10: yading@10: int width = output->PicInfo.width; yading@10: int height = output->PicInfo.height; yading@10: int bwidth; yading@10: uint8_t *src = output->Ybuff; yading@10: int sStride; yading@10: uint8_t *dst; yading@10: int dStride; yading@10: yading@10: if (output->PicInfo.timeStamp != 0) { yading@10: OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp); yading@10: if (node) { yading@10: pkt_pts = node->reordered_opaque; yading@10: pic_type = node->pic_type; yading@10: av_free(node); yading@10: } else { yading@10: /* yading@10: * We will encounter a situation where a timestamp cannot be yading@10: * popped if a second field is being returned. In this case, yading@10: * each field has the same timestamp and the first one will yading@10: * cause it to be popped. To keep subsequent calculations yading@10: * simple, pic_type should be set a FIELD value - doesn't yading@10: * matter which, but I chose BOTTOM. yading@10: */ yading@10: pic_type = PICT_BOTTOM_FIELD; yading@10: } yading@10: av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n", yading@10: output->PicInfo.timeStamp); yading@10: av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n", yading@10: pic_type); yading@10: } yading@10: yading@10: ret = DtsGetDriverStatus(priv->dev, &decoder_status); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, yading@10: "CrystalHD: GetDriverStatus failed: %u\n", ret); yading@10: return RET_ERROR; yading@10: } yading@10: yading@10: /* yading@10: * For most content, we can trust the interlaced flag returned yading@10: * by the hardware, but sometimes we can't. These are the yading@10: * conditions under which we can trust the flag: yading@10: * yading@10: * 1) It's not h.264 content yading@10: * 2) The UNKNOWN_SRC flag is not set yading@10: * 3) We know we're expecting a second field yading@10: * 4) The hardware reports this picture and the next picture yading@10: * have the same picture number. yading@10: * yading@10: * Note that there can still be interlaced content that will yading@10: * fail this check, if the hardware hasn't decoded the next yading@10: * picture or if there is a corruption in the stream. (In either yading@10: * case a 0 will be returned for the next picture number) yading@10: */ yading@10: trust_interlaced = avctx->codec->id != AV_CODEC_ID_H264 || yading@10: !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) || yading@10: priv->need_second_field || yading@10: (decoder_status.picNumFlags & ~0x40000000) == yading@10: output->PicInfo.picture_number; yading@10: yading@10: /* yading@10: * If we got a false negative for trust_interlaced on the first field, yading@10: * we will realise our mistake here when we see that the picture number is that yading@10: * of the previous picture. We cannot recover the frame and should discard the yading@10: * second field to keep the correct number of output frames. yading@10: */ yading@10: if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "Incorrectly guessed progressive frame. Discarding second field\n"); yading@10: /* Returning without providing a picture. */ yading@10: return RET_OK; yading@10: } yading@10: yading@10: interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && yading@10: trust_interlaced; yading@10: yading@10: if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) { yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "Next picture number unknown. Assuming progressive frame.\n"); yading@10: } yading@10: yading@10: av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n", yading@10: interlaced, trust_interlaced); yading@10: yading@10: if (priv->pic->data[0] && !priv->need_second_field) yading@10: av_frame_unref(priv->pic); yading@10: yading@10: priv->need_second_field = interlaced && !priv->need_second_field; yading@10: yading@10: if (!priv->pic->data[0]) { yading@10: if (ff_get_buffer(avctx, priv->pic, AV_GET_BUFFER_FLAG_REF) < 0) yading@10: return RET_ERROR; yading@10: } yading@10: yading@10: bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0); yading@10: if (priv->is_70012) { yading@10: int pStride; yading@10: yading@10: if (width <= 720) yading@10: pStride = 720; yading@10: else if (width <= 1280) yading@10: pStride = 1280; yading@10: else pStride = 1920; yading@10: sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0); yading@10: } else { yading@10: sStride = bwidth; yading@10: } yading@10: yading@10: dStride = priv->pic->linesize[0]; yading@10: dst = priv->pic->data[0]; yading@10: yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n"); yading@10: yading@10: if (interlaced) { yading@10: int dY = 0; yading@10: int sY = 0; yading@10: yading@10: height /= 2; yading@10: if (bottom_field) { yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n"); yading@10: dY = 1; yading@10: } else { yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n"); yading@10: dY = 0; yading@10: } yading@10: yading@10: for (sY = 0; sY < height; dY++, sY++) { yading@10: memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth); yading@10: dY++; yading@10: } yading@10: } else { yading@10: av_image_copy_plane(dst, dStride, src, sStride, bwidth, height); yading@10: } yading@10: yading@10: priv->pic->interlaced_frame = interlaced; yading@10: if (interlaced) yading@10: priv->pic->top_field_first = !bottom_first; yading@10: yading@10: priv->pic->pkt_pts = pkt_pts; yading@10: yading@10: if (!priv->need_second_field) { yading@10: *got_frame = 1; yading@10: if ((ret = av_frame_ref(data, priv->pic)) < 0) { yading@10: return ret; yading@10: } yading@10: } yading@10: yading@10: /* yading@10: * Two types of PAFF content have been observed. One form causes the yading@10: * hardware to return a field pair and the other individual fields, yading@10: * even though the input is always individual fields. We must skip yading@10: * copying on the next decode() call to maintain pipeline length in yading@10: * the first case. yading@10: */ yading@10: if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) && yading@10: (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) { yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); yading@10: return RET_SKIP_NEXT_COPY; yading@10: } yading@10: yading@10: /* yading@10: * The logic here is purely based on empirical testing with samples. yading@10: * If we need a second field, it could come from a second input packet, yading@10: * or it could come from the same field-pair input packet at the current yading@10: * field. In the first case, we should return and wait for the next time yading@10: * round to get the second field, while in the second case, we should yading@10: * ask the decoder for it immediately. yading@10: * yading@10: * Testing has shown that we are dealing with the fieldpair -> two fields yading@10: * case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture yading@10: * type was PICT_FRAME (in this second case, the flag might still be set) yading@10: */ yading@10: return priv->need_second_field && yading@10: (!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) || yading@10: pic_type == PICT_FRAME) ? yading@10: RET_COPY_NEXT_FIELD : RET_OK; yading@10: } yading@10: yading@10: yading@10: static inline CopyRet receive_frame(AVCodecContext *avctx, yading@10: void *data, int *got_frame) yading@10: { yading@10: BC_STATUS ret; yading@10: BC_DTS_PROC_OUT output = { yading@10: .PicInfo.width = avctx->width, yading@10: .PicInfo.height = avctx->height, yading@10: }; yading@10: CHDContext *priv = avctx->priv_data; yading@10: HANDLE dev = priv->dev; yading@10: yading@10: *got_frame = 0; yading@10: yading@10: // Request decoded data from the driver yading@10: ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output); yading@10: if (ret == BC_STS_FMT_CHANGE) { yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n"); yading@10: avctx->width = output.PicInfo.width; yading@10: avctx->height = output.PicInfo.height; yading@10: switch ( output.PicInfo.aspect_ratio ) { yading@10: case vdecAspectRatioSquare: yading@10: avctx->sample_aspect_ratio = (AVRational) { 1, 1}; yading@10: break; yading@10: case vdecAspectRatio12_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 12, 11}; yading@10: break; yading@10: case vdecAspectRatio10_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 10, 11}; yading@10: break; yading@10: case vdecAspectRatio16_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 16, 11}; yading@10: break; yading@10: case vdecAspectRatio40_33: yading@10: avctx->sample_aspect_ratio = (AVRational) { 40, 33}; yading@10: break; yading@10: case vdecAspectRatio24_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 24, 11}; yading@10: break; yading@10: case vdecAspectRatio20_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 20, 11}; yading@10: break; yading@10: case vdecAspectRatio32_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 32, 11}; yading@10: break; yading@10: case vdecAspectRatio80_33: yading@10: avctx->sample_aspect_ratio = (AVRational) { 80, 33}; yading@10: break; yading@10: case vdecAspectRatio18_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 18, 11}; yading@10: break; yading@10: case vdecAspectRatio15_11: yading@10: avctx->sample_aspect_ratio = (AVRational) { 15, 11}; yading@10: break; yading@10: case vdecAspectRatio64_33: yading@10: avctx->sample_aspect_ratio = (AVRational) { 64, 33}; yading@10: break; yading@10: case vdecAspectRatio160_99: yading@10: avctx->sample_aspect_ratio = (AVRational) {160, 99}; yading@10: break; yading@10: case vdecAspectRatio4_3: yading@10: avctx->sample_aspect_ratio = (AVRational) { 4, 3}; yading@10: break; yading@10: case vdecAspectRatio16_9: yading@10: avctx->sample_aspect_ratio = (AVRational) { 16, 9}; yading@10: break; yading@10: case vdecAspectRatio221_1: yading@10: avctx->sample_aspect_ratio = (AVRational) {221, 1}; yading@10: break; yading@10: } yading@10: return RET_COPY_AGAIN; yading@10: } else if (ret == BC_STS_SUCCESS) { yading@10: int copy_ret = -1; yading@10: if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) { yading@10: if (priv->last_picture == -1) { yading@10: /* yading@10: * Init to one less, so that the incrementing code doesn't yading@10: * need to be special-cased. yading@10: */ yading@10: priv->last_picture = output.PicInfo.picture_number - 1; yading@10: } yading@10: yading@10: if (avctx->codec->id == AV_CODEC_ID_MPEG4 && yading@10: output.PicInfo.timeStamp == 0 && priv->bframe_bug) { yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "CrystalHD: Not returning packed frame twice.\n"); yading@10: priv->last_picture++; yading@10: DtsReleaseOutputBuffs(dev, NULL, FALSE); yading@10: return RET_COPY_AGAIN; yading@10: } yading@10: yading@10: print_frame_info(priv, &output); yading@10: yading@10: if (priv->last_picture + 1 < output.PicInfo.picture_number) { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "CrystalHD: Picture Number discontinuity\n"); yading@10: /* yading@10: * Have we lost frames? If so, we need to shrink the yading@10: * pipeline length appropriately. yading@10: * yading@10: * XXX: I have no idea what the semantics of this situation yading@10: * are so I don't even know if we've lost frames or which yading@10: * ones. yading@10: * yading@10: * In any case, only warn the first time. yading@10: */ yading@10: priv->last_picture = output.PicInfo.picture_number - 1; yading@10: } yading@10: yading@10: copy_ret = copy_frame(avctx, &output, data, got_frame); yading@10: if (*got_frame > 0) { yading@10: avctx->has_b_frames--; yading@10: priv->last_picture++; yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n", yading@10: avctx->has_b_frames); yading@10: } yading@10: } else { yading@10: /* yading@10: * An invalid frame has been consumed. yading@10: */ yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with " yading@10: "invalid PIB\n"); yading@10: avctx->has_b_frames--; yading@10: copy_ret = RET_OK; yading@10: } yading@10: DtsReleaseOutputBuffs(dev, NULL, FALSE); yading@10: yading@10: return copy_ret; yading@10: } else if (ret == BC_STS_BUSY) { yading@10: return RET_COPY_AGAIN; yading@10: } else { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret); yading@10: return RET_ERROR; yading@10: } yading@10: } yading@10: yading@10: yading@10: static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) yading@10: { yading@10: BC_STATUS ret; yading@10: BC_DTS_STATUS decoder_status = { 0, }; yading@10: CopyRet rec_ret; yading@10: CHDContext *priv = avctx->priv_data; yading@10: HANDLE dev = priv->dev; yading@10: uint8_t *in_data = avpkt->data; yading@10: int len = avpkt->size; yading@10: int free_data = 0; yading@10: uint8_t pic_type = 0; yading@10: yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n"); yading@10: yading@10: if (avpkt->size == 7 && !priv->bframe_bug) { yading@10: /* yading@10: * The use of a drop frame triggers the bug yading@10: */ yading@10: av_log(avctx, AV_LOG_INFO, yading@10: "CrystalHD: Enabling work-around for packed b-frame bug\n"); yading@10: priv->bframe_bug = 1; yading@10: } else if (avpkt->size == 8 && priv->bframe_bug) { yading@10: /* yading@10: * Delay frames don't trigger the bug yading@10: */ yading@10: av_log(avctx, AV_LOG_INFO, yading@10: "CrystalHD: Disabling work-around for packed b-frame bug\n"); yading@10: priv->bframe_bug = 0; yading@10: } yading@10: yading@10: if (len) { yading@10: int32_t tx_free = (int32_t)DtsTxFreeSize(dev); yading@10: yading@10: if (priv->parser) { yading@10: int ret = 0; yading@10: yading@10: if (priv->bsfc) { yading@10: ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL, yading@10: &in_data, &len, yading@10: avpkt->data, len, 0); yading@10: } yading@10: free_data = ret > 0; yading@10: yading@10: if (ret >= 0) { yading@10: uint8_t *pout; yading@10: int psize; yading@10: int index; yading@10: H264Context *h = priv->parser->priv_data; yading@10: yading@10: index = av_parser_parse2(priv->parser, avctx, &pout, &psize, yading@10: in_data, len, avctx->pkt->pts, yading@10: avctx->pkt->dts, 0); yading@10: if (index < 0) { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "CrystalHD: Failed to parse h.264 packet to " yading@10: "detect interlacing.\n"); yading@10: } else if (index != len) { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "CrystalHD: Failed to parse h.264 packet " yading@10: "completely. Interlaced frames may be " yading@10: "incorrectly detected.\n"); yading@10: } else { yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "CrystalHD: parser picture type %d\n", yading@10: h->picture_structure); yading@10: pic_type = h->picture_structure; yading@10: } yading@10: } else { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "CrystalHD: mp4toannexb filter failed to filter " yading@10: "packet. Interlaced frames may be incorrectly " yading@10: "detected.\n"); yading@10: } yading@10: } yading@10: yading@10: if (len < tx_free - 1024) { yading@10: /* yading@10: * Despite being notionally opaque, either libcrystalhd or yading@10: * the hardware itself will mangle pts values that are too yading@10: * small or too large. The docs claim it should be in units yading@10: * of 100ns. Given that we're nominally dealing with a black yading@10: * box on both sides, any transform we do has no guarantee of yading@10: * avoiding mangling so we need to build a mapping to values yading@10: * we know will not be mangled. yading@10: */ yading@10: uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type); yading@10: if (!pts) { yading@10: if (free_data) { yading@10: av_freep(&in_data); yading@10: } yading@10: return AVERROR(ENOMEM); yading@10: } yading@10: av_log(priv->avctx, AV_LOG_VERBOSE, yading@10: "input \"pts\": %"PRIu64"\n", pts); yading@10: ret = DtsProcInput(dev, in_data, len, pts, 0); yading@10: if (free_data) { yading@10: av_freep(&in_data); yading@10: } yading@10: if (ret == BC_STS_BUSY) { yading@10: av_log(avctx, AV_LOG_WARNING, yading@10: "CrystalHD: ProcInput returned busy\n"); yading@10: usleep(BASE_WAIT); yading@10: return AVERROR(EBUSY); yading@10: } else if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, yading@10: "CrystalHD: ProcInput failed: %u\n", ret); yading@10: return -1; yading@10: } yading@10: avctx->has_b_frames++; yading@10: } else { yading@10: av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n"); yading@10: len = 0; // We didn't consume any bytes. yading@10: } yading@10: } else { yading@10: av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n"); yading@10: } yading@10: yading@10: if (priv->skip_next_output) { yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n"); yading@10: priv->skip_next_output = 0; yading@10: avctx->has_b_frames--; yading@10: return len; yading@10: } yading@10: yading@10: ret = DtsGetDriverStatus(dev, &decoder_status); yading@10: if (ret != BC_STS_SUCCESS) { yading@10: av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n"); yading@10: return -1; yading@10: } yading@10: yading@10: /* yading@10: * No frames ready. Don't try to extract. yading@10: * yading@10: * Empirical testing shows that ReadyListCount can be a damn lie, yading@10: * and ProcOut still fails when count > 0. The same testing showed yading@10: * that two more iterations were needed before ProcOutput would yading@10: * succeed. yading@10: */ yading@10: if (priv->output_ready < 2) { yading@10: if (decoder_status.ReadyListCount != 0) yading@10: priv->output_ready++; yading@10: usleep(BASE_WAIT); yading@10: av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n"); yading@10: return len; yading@10: } else if (decoder_status.ReadyListCount == 0) { yading@10: /* yading@10: * After the pipeline is established, if we encounter a lack of frames yading@10: * that probably means we're not giving the hardware enough time to yading@10: * decode them, so start increasing the wait time at the end of a yading@10: * decode call. yading@10: */ yading@10: usleep(BASE_WAIT); yading@10: priv->decode_wait += WAIT_UNIT; yading@10: av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n"); yading@10: return len; yading@10: } yading@10: yading@10: do { yading@10: rec_ret = receive_frame(avctx, data, got_frame); yading@10: if (rec_ret == RET_OK && *got_frame == 0) { yading@10: /* yading@10: * This case is for when the encoded fields are stored yading@10: * separately and we get a separate avpkt for each one. To keep yading@10: * the pipeline stable, we should return nothing and wait for yading@10: * the next time round to grab the second field. yading@10: * H.264 PAFF is an example of this. yading@10: */ yading@10: av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n"); yading@10: avctx->has_b_frames--; yading@10: } else if (rec_ret == RET_COPY_NEXT_FIELD) { yading@10: /* yading@10: * This case is for when the encoded fields are stored in a yading@10: * single avpkt but the hardware returns then separately. Unless yading@10: * we grab the second field before returning, we'll slip another yading@10: * frame in the pipeline and if that happens a lot, we're sunk. yading@10: * So we have to get that second field now. yading@10: * Interlaced mpeg2 and vc1 are examples of this. yading@10: */ yading@10: av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n"); yading@10: while (1) { yading@10: usleep(priv->decode_wait); yading@10: ret = DtsGetDriverStatus(dev, &decoder_status); yading@10: if (ret == BC_STS_SUCCESS && yading@10: decoder_status.ReadyListCount > 0) { yading@10: rec_ret = receive_frame(avctx, data, got_frame); yading@10: if ((rec_ret == RET_OK && *got_frame > 0) || yading@10: rec_ret == RET_ERROR) yading@10: break; yading@10: } yading@10: } yading@10: av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n"); yading@10: } else if (rec_ret == RET_SKIP_NEXT_COPY) { yading@10: /* yading@10: * Two input packets got turned into a field pair. Gawd. yading@10: */ yading@10: av_log(avctx, AV_LOG_VERBOSE, yading@10: "Don't output on next decode call.\n"); yading@10: priv->skip_next_output = 1; yading@10: } yading@10: /* yading@10: * If rec_ret == RET_COPY_AGAIN, that means that either we just handled yading@10: * a FMT_CHANGE event and need to go around again for the actual frame, yading@10: * we got a busy status and need to try again, or we're dealing with yading@10: * packed b-frames, where the hardware strangely returns the packed yading@10: * p-frame twice. We choose to keep the second copy as it carries the yading@10: * valid pts. yading@10: */ yading@10: } while (rec_ret == RET_COPY_AGAIN); yading@10: usleep(priv->decode_wait); yading@10: return len; yading@10: } yading@10: yading@10: yading@10: #if CONFIG_H264_CRYSTALHD_DECODER yading@10: static AVClass h264_class = { yading@10: "h264_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_h264_crystalhd_decoder = { yading@10: .name = "h264_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_H264, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &h264_class, yading@10: }; yading@10: #endif yading@10: yading@10: #if CONFIG_MPEG2_CRYSTALHD_DECODER yading@10: static AVClass mpeg2_class = { yading@10: "mpeg2_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_mpeg2_crystalhd_decoder = { yading@10: .name = "mpeg2_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_MPEG2VIDEO, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &mpeg2_class, yading@10: }; yading@10: #endif yading@10: yading@10: #if CONFIG_MPEG4_CRYSTALHD_DECODER yading@10: static AVClass mpeg4_class = { yading@10: "mpeg4_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_mpeg4_crystalhd_decoder = { yading@10: .name = "mpeg4_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_MPEG4, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &mpeg4_class, yading@10: }; yading@10: #endif yading@10: yading@10: #if CONFIG_MSMPEG4_CRYSTALHD_DECODER yading@10: static AVClass msmpeg4_class = { yading@10: "msmpeg4_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_msmpeg4_crystalhd_decoder = { yading@10: .name = "msmpeg4_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_MSMPEG4V3, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &msmpeg4_class, yading@10: }; yading@10: #endif yading@10: yading@10: #if CONFIG_VC1_CRYSTALHD_DECODER yading@10: static AVClass vc1_class = { yading@10: "vc1_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_vc1_crystalhd_decoder = { yading@10: .name = "vc1_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_VC1, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &vc1_class, yading@10: }; yading@10: #endif yading@10: yading@10: #if CONFIG_WMV3_CRYSTALHD_DECODER yading@10: static AVClass wmv3_class = { yading@10: "wmv3_crystalhd", yading@10: av_default_item_name, yading@10: options, yading@10: LIBAVUTIL_VERSION_INT, yading@10: }; yading@10: yading@10: AVCodec ff_wmv3_crystalhd_decoder = { yading@10: .name = "wmv3_crystalhd", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_WMV3, yading@10: .priv_data_size = sizeof(CHDContext), yading@10: .init = init, yading@10: .close = uninit, yading@10: .decode = decode, yading@10: .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, yading@10: .flush = flush, yading@10: .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"), yading@10: .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE}, yading@10: .priv_class = &wmv3_class, yading@10: }; yading@10: #endif