You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1224 lines
43KB

  1. /*
  2. * - CrystalHD decoder module -
  3. *
  4. * Copyright(C) 2010,2011 Philip Langdale <ffmpeg.philipl@overt.org>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /*
  23. * - Principles of Operation -
  24. *
  25. * The CrystalHD decoder operates at the bitstream level - which is an even
  26. * higher level than the decoding hardware you typically see in modern GPUs.
  27. * This means it has a very simple interface, in principle. You feed demuxed
  28. * packets in one end and get decoded picture (fields/frames) out the other.
  29. *
  30. * Of course, nothing is ever that simple. Due, at the very least, to b-frame
  31. * dependencies in the supported formats, the hardware has a delay between
  32. * when a packet goes in, and when a picture comes out. Furthermore, this delay
  33. * is not just a function of time, but also one of the dependency on additional
  34. * frames being fed into the decoder to satisfy the b-frame dependencies.
  35. *
  36. * As such, a pipeline will build up that is roughly equivalent to the required
  37. * DPB for the file being played. If that was all it took, things would still
  38. * be simple - so, of course, it isn't.
  39. *
  40. * The hardware has a way of indicating that a picture is ready to be copied out,
  41. * but this is unreliable - and sometimes the attempt will still fail so, based
  42. * on testing, the code will wait until 3 pictures are ready before starting
  43. * to copy out - and this has the effect of extending the pipeline.
  44. *
  45. * Finally, while it is tempting to say that once the decoder starts outputting
  46. * frames, the software should never fail to return a frame from a decode(),
  47. * this is a hard assertion to make, because the stream may switch between
  48. * differently encoded content (number of b-frames, interlacing, etc) which
  49. * might require a longer pipeline than before. If that happened, you could
  50. * deadlock trying to retrieve a frame that can't be decoded without feeding
  51. * in additional packets.
  52. *
  53. * As such, the code will return in the event that a picture cannot be copied
  54. * out, leading to an increase in the length of the pipeline. This in turn,
  55. * means we have to be sensitive to the time it takes to decode a picture;
  56. * We do not want to give up just because the hardware needed a little more
  57. * time to prepare the picture! For this reason, there are delays included
  58. * in the decode() path that ensure that, under normal conditions, the hardware
  59. * will only fail to return a frame if it really needs additional packets to
  60. * complete the decoding.
  61. *
  62. * Finally, to be explicit, we do not want the pipeline to grow without bound
  63. * for two reasons: 1) The hardware can only buffer a finite number of packets,
  64. * and 2) The client application may not be able to cope with arbitrarily long
  65. * delays in the video path relative to the audio path. For example. MPlayer
  66. * can only handle a 20 picture delay (although this is arbitrary, and needs
  67. * to be extended to fully support the CrystalHD where the delay could be up
  68. * to 32 pictures - consider PAFF H.264 content with 16 b-frames).
  69. */
  70. /*****************************************************************************
  71. * Includes
  72. ****************************************************************************/
  73. #define _XOPEN_SOURCE 600
  74. #include <inttypes.h>
  75. #include <stdio.h>
  76. #include <stdlib.h>
  77. #include <unistd.h>
  78. #include <libcrystalhd/bc_dts_types.h>
  79. #include <libcrystalhd/bc_dts_defs.h>
  80. #include <libcrystalhd/libcrystalhd_if.h>
  81. #include "avcodec.h"
  82. #include "h264.h"
  83. #include "internal.h"
  84. #include "libavutil/imgutils.h"
  85. #include "libavutil/intreadwrite.h"
  86. #include "libavutil/opt.h"
  87. /** Timeout parameter passed to DtsProcOutput() in us */
  88. #define OUTPUT_PROC_TIMEOUT 50
  89. /** Step between fake timestamps passed to hardware in units of 100ns */
  90. #define TIMESTAMP_UNIT 100000
  91. /** Initial value in us of the wait in decode() */
  92. #define BASE_WAIT 10000
  93. /** Increment in us to adjust wait in decode() */
  94. #define WAIT_UNIT 1000
  95. /*****************************************************************************
  96. * Module private data
  97. ****************************************************************************/
  98. typedef enum {
  99. RET_ERROR = -1,
  100. RET_OK = 0,
  101. RET_COPY_AGAIN = 1,
  102. RET_SKIP_NEXT_COPY = 2,
  103. RET_COPY_NEXT_FIELD = 3,
  104. } CopyRet;
  105. typedef struct OpaqueList {
  106. struct OpaqueList *next;
  107. uint64_t fake_timestamp;
  108. uint64_t reordered_opaque;
  109. uint8_t pic_type;
  110. } OpaqueList;
  111. typedef struct {
  112. AVClass *av_class;
  113. AVCodecContext *avctx;
  114. AVFrame *pic;
  115. HANDLE dev;
  116. uint8_t *orig_extradata;
  117. uint32_t orig_extradata_size;
  118. AVBitStreamFilterContext *bsfc;
  119. AVCodecParserContext *parser;
  120. uint8_t is_70012;
  121. uint8_t *sps_pps_buf;
  122. uint32_t sps_pps_size;
  123. uint8_t is_nal;
  124. uint8_t output_ready;
  125. uint8_t need_second_field;
  126. uint8_t skip_next_output;
  127. uint64_t decode_wait;
  128. uint64_t last_picture;
  129. OpaqueList *head;
  130. OpaqueList *tail;
  131. /* Options */
  132. uint32_t sWidth;
  133. uint8_t bframe_bug;
  134. } CHDContext;
  135. static const AVOption options[] = {
  136. { "crystalhd_downscale_width",
  137. "Turn on downscaling to the specified width",
  138. offsetof(CHDContext, sWidth),
  139. AV_OPT_TYPE_INT, {.i64 = 0}, 0, UINT32_MAX,
  140. AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, },
  141. { NULL, },
  142. };
  143. /*****************************************************************************
  144. * Helper functions
  145. ****************************************************************************/
  146. static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum AVCodecID id)
  147. {
  148. switch (id) {
  149. case AV_CODEC_ID_MPEG4:
  150. return BC_MSUBTYPE_DIVX;
  151. case AV_CODEC_ID_MSMPEG4V3:
  152. return BC_MSUBTYPE_DIVX311;
  153. case AV_CODEC_ID_MPEG2VIDEO:
  154. return BC_MSUBTYPE_MPEG2VIDEO;
  155. case AV_CODEC_ID_VC1:
  156. return BC_MSUBTYPE_VC1;
  157. case AV_CODEC_ID_WMV3:
  158. return BC_MSUBTYPE_WMV3;
  159. case AV_CODEC_ID_H264:
  160. return priv->is_nal ? BC_MSUBTYPE_AVC1 : BC_MSUBTYPE_H264;
  161. default:
  162. return BC_MSUBTYPE_INVALID;
  163. }
  164. }
  165. static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output)
  166. {
  167. av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz);
  168. av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n",
  169. output->YBuffDoneSz);
  170. av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n",
  171. output->UVBuffDoneSz);
  172. av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n",
  173. output->PicInfo.timeStamp);
  174. av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n",
  175. output->PicInfo.picture_number);
  176. av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n",
  177. output->PicInfo.width);
  178. av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n",
  179. output->PicInfo.height);
  180. av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n",
  181. output->PicInfo.chroma_format);
  182. av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n",
  183. output->PicInfo.pulldown);
  184. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n",
  185. output->PicInfo.flags);
  186. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n",
  187. output->PicInfo.frame_rate);
  188. av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n",
  189. output->PicInfo.aspect_ratio);
  190. av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n",
  191. output->PicInfo.colour_primaries);
  192. av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n",
  193. output->PicInfo.picture_meta_payload);
  194. av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n",
  195. output->PicInfo.sess_num);
  196. av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n",
  197. output->PicInfo.ycom);
  198. av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n",
  199. output->PicInfo.custom_aspect_ratio_width_height);
  200. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n",
  201. output->PicInfo.n_drop);
  202. av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n",
  203. output->PicInfo.other.h264.valid);
  204. }
  205. /*****************************************************************************
  206. * OpaqueList functions
  207. ****************************************************************************/
  208. static uint64_t opaque_list_push(CHDContext *priv, uint64_t reordered_opaque,
  209. uint8_t pic_type)
  210. {
  211. OpaqueList *newNode = av_mallocz(sizeof (OpaqueList));
  212. if (!newNode) {
  213. av_log(priv->avctx, AV_LOG_ERROR,
  214. "Unable to allocate new node in OpaqueList.\n");
  215. return 0;
  216. }
  217. if (!priv->head) {
  218. newNode->fake_timestamp = TIMESTAMP_UNIT;
  219. priv->head = newNode;
  220. } else {
  221. newNode->fake_timestamp = priv->tail->fake_timestamp + TIMESTAMP_UNIT;
  222. priv->tail->next = newNode;
  223. }
  224. priv->tail = newNode;
  225. newNode->reordered_opaque = reordered_opaque;
  226. newNode->pic_type = pic_type;
  227. return newNode->fake_timestamp;
  228. }
  229. /*
  230. * The OpaqueList is built in decode order, while elements will be removed
  231. * in presentation order. If frames are reordered, this means we must be
  232. * able to remove elements that are not the first element.
  233. *
  234. * Returned node must be freed by caller.
  235. */
  236. static OpaqueList *opaque_list_pop(CHDContext *priv, uint64_t fake_timestamp)
  237. {
  238. OpaqueList *node = priv->head;
  239. if (!priv->head) {
  240. av_log(priv->avctx, AV_LOG_ERROR,
  241. "CrystalHD: Attempted to query non-existent timestamps.\n");
  242. return NULL;
  243. }
  244. /*
  245. * The first element is special-cased because we have to manipulate
  246. * the head pointer rather than the previous element in the list.
  247. */
  248. if (priv->head->fake_timestamp == fake_timestamp) {
  249. priv->head = node->next;
  250. if (!priv->head->next)
  251. priv->tail = priv->head;
  252. node->next = NULL;
  253. return node;
  254. }
  255. /*
  256. * The list is processed at arm's length so that we have the
  257. * previous element available to rewrite its next pointer.
  258. */
  259. while (node->next) {
  260. OpaqueList *current = node->next;
  261. if (current->fake_timestamp == fake_timestamp) {
  262. node->next = current->next;
  263. if (!node->next)
  264. priv->tail = node;
  265. current->next = NULL;
  266. return current;
  267. } else {
  268. node = current;
  269. }
  270. }
  271. av_log(priv->avctx, AV_LOG_VERBOSE,
  272. "CrystalHD: Couldn't match fake_timestamp.\n");
  273. return NULL;
  274. }
  275. /*****************************************************************************
  276. * Video decoder API function definitions
  277. ****************************************************************************/
  278. static void flush(AVCodecContext *avctx)
  279. {
  280. CHDContext *priv = avctx->priv_data;
  281. avctx->has_b_frames = 0;
  282. priv->last_picture = -1;
  283. priv->output_ready = 0;
  284. priv->need_second_field = 0;
  285. priv->skip_next_output = 0;
  286. priv->decode_wait = BASE_WAIT;
  287. av_frame_unref (priv->pic);
  288. /* Flush mode 4 flushes all software and hardware buffers. */
  289. DtsFlushInput(priv->dev, 4);
  290. }
  291. static av_cold int uninit(AVCodecContext *avctx)
  292. {
  293. CHDContext *priv = avctx->priv_data;
  294. HANDLE device;
  295. device = priv->dev;
  296. DtsStopDecoder(device);
  297. DtsCloseDecoder(device);
  298. DtsDeviceClose(device);
  299. /*
  300. * Restore original extradata, so that if the decoder is
  301. * reinitialised, the bitstream detection and filtering
  302. * will work as expected.
  303. */
  304. if (priv->orig_extradata) {
  305. av_free(avctx->extradata);
  306. avctx->extradata = priv->orig_extradata;
  307. avctx->extradata_size = priv->orig_extradata_size;
  308. priv->orig_extradata = NULL;
  309. priv->orig_extradata_size = 0;
  310. }
  311. av_parser_close(priv->parser);
  312. if (priv->bsfc) {
  313. av_bitstream_filter_close(priv->bsfc);
  314. }
  315. av_free(priv->sps_pps_buf);
  316. av_frame_free (&priv->pic);
  317. if (priv->head) {
  318. OpaqueList *node = priv->head;
  319. while (node) {
  320. OpaqueList *next = node->next;
  321. av_free(node);
  322. node = next;
  323. }
  324. }
  325. return 0;
  326. }
  327. static av_cold int init(AVCodecContext *avctx)
  328. {
  329. CHDContext* priv;
  330. BC_STATUS ret;
  331. BC_INFO_CRYSTAL version;
  332. BC_INPUT_FORMAT format = {
  333. .FGTEnable = FALSE,
  334. .Progressive = TRUE,
  335. .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40,
  336. .width = avctx->width,
  337. .height = avctx->height,
  338. };
  339. BC_MEDIA_SUBTYPE subtype;
  340. uint32_t mode = DTS_PLAYBACK_MODE |
  341. DTS_LOAD_FILE_PLAY_FW |
  342. DTS_SKIP_TX_CHK_CPB |
  343. DTS_PLAYBACK_DROP_RPT_MODE |
  344. DTS_SINGLE_THREADED_MODE |
  345. DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976);
  346. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n",
  347. avctx->codec->name);
  348. avctx->pix_fmt = AV_PIX_FMT_YUYV422;
  349. /* Initialize the library */
  350. priv = avctx->priv_data;
  351. priv->avctx = avctx;
  352. priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1;
  353. priv->last_picture = -1;
  354. priv->decode_wait = BASE_WAIT;
  355. priv->pic = av_frame_alloc();
  356. subtype = id2subtype(priv, avctx->codec->id);
  357. switch (subtype) {
  358. case BC_MSUBTYPE_AVC1:
  359. {
  360. uint8_t *dummy_p;
  361. int dummy_int;
  362. /* Back up the extradata so it can be restored at close time. */
  363. priv->orig_extradata = av_malloc(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
  364. if (!priv->orig_extradata) {
  365. av_log(avctx, AV_LOG_ERROR,
  366. "Failed to allocate copy of extradata\n");
  367. return AVERROR(ENOMEM);
  368. }
  369. priv->orig_extradata_size = avctx->extradata_size;
  370. memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size);
  371. priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
  372. if (!priv->bsfc) {
  373. av_log(avctx, AV_LOG_ERROR,
  374. "Cannot open the h264_mp4toannexb BSF!\n");
  375. return AVERROR_BSF_NOT_FOUND;
  376. }
  377. av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p,
  378. &dummy_int, NULL, 0, 0);
  379. }
  380. subtype = BC_MSUBTYPE_H264;
  381. // Fall-through
  382. case BC_MSUBTYPE_H264:
  383. format.startCodeSz = 4;
  384. // Fall-through
  385. case BC_MSUBTYPE_VC1:
  386. case BC_MSUBTYPE_WVC1:
  387. case BC_MSUBTYPE_WMV3:
  388. case BC_MSUBTYPE_WMVA:
  389. case BC_MSUBTYPE_MPEG2VIDEO:
  390. case BC_MSUBTYPE_DIVX:
  391. case BC_MSUBTYPE_DIVX311:
  392. format.pMetaData = avctx->extradata;
  393. format.metaDataSz = avctx->extradata_size;
  394. break;
  395. default:
  396. av_log(avctx, AV_LOG_ERROR, "CrystalHD: Unknown codec name\n");
  397. return AVERROR(EINVAL);
  398. }
  399. format.mSubtype = subtype;
  400. if (priv->sWidth) {
  401. format.bEnableScaling = 1;
  402. format.ScalingParams.sWidth = priv->sWidth;
  403. }
  404. /* Get a decoder instance */
  405. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: starting up\n");
  406. // Initialize the Link and Decoder devices
  407. ret = DtsDeviceOpen(&priv->dev, mode);
  408. if (ret != BC_STS_SUCCESS) {
  409. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: DtsDeviceOpen failed\n");
  410. goto fail;
  411. }
  412. ret = DtsCrystalHDVersion(priv->dev, &version);
  413. if (ret != BC_STS_SUCCESS) {
  414. av_log(avctx, AV_LOG_VERBOSE,
  415. "CrystalHD: DtsCrystalHDVersion failed\n");
  416. goto fail;
  417. }
  418. priv->is_70012 = version.device == 0;
  419. if (priv->is_70012 &&
  420. (subtype == BC_MSUBTYPE_DIVX || subtype == BC_MSUBTYPE_DIVX311)) {
  421. av_log(avctx, AV_LOG_VERBOSE,
  422. "CrystalHD: BCM70012 doesn't support MPEG4-ASP/DivX/Xvid\n");
  423. goto fail;
  424. }
  425. ret = DtsSetInputFormat(priv->dev, &format);
  426. if (ret != BC_STS_SUCCESS) {
  427. av_log(avctx, AV_LOG_ERROR, "CrystalHD: SetInputFormat failed\n");
  428. goto fail;
  429. }
  430. ret = DtsOpenDecoder(priv->dev, BC_STREAM_TYPE_ES);
  431. if (ret != BC_STS_SUCCESS) {
  432. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsOpenDecoder failed\n");
  433. goto fail;
  434. }
  435. ret = DtsSetColorSpace(priv->dev, OUTPUT_MODE422_YUY2);
  436. if (ret != BC_STS_SUCCESS) {
  437. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsSetColorSpace failed\n");
  438. goto fail;
  439. }
  440. ret = DtsStartDecoder(priv->dev);
  441. if (ret != BC_STS_SUCCESS) {
  442. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartDecoder failed\n");
  443. goto fail;
  444. }
  445. ret = DtsStartCapture(priv->dev);
  446. if (ret != BC_STS_SUCCESS) {
  447. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartCapture failed\n");
  448. goto fail;
  449. }
  450. if (avctx->codec->id == AV_CODEC_ID_H264) {
  451. priv->parser = av_parser_init(avctx->codec->id);
  452. if (!priv->parser)
  453. av_log(avctx, AV_LOG_WARNING,
  454. "Cannot open the h.264 parser! Interlaced h.264 content "
  455. "will not be detected reliably.\n");
  456. priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES;
  457. }
  458. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n");
  459. return 0;
  460. fail:
  461. uninit(avctx);
  462. return -1;
  463. }
  464. static inline CopyRet copy_frame(AVCodecContext *avctx,
  465. BC_DTS_PROC_OUT *output,
  466. void *data, int *got_frame)
  467. {
  468. BC_STATUS ret;
  469. BC_DTS_STATUS decoder_status = { 0, };
  470. uint8_t trust_interlaced;
  471. uint8_t interlaced;
  472. CHDContext *priv = avctx->priv_data;
  473. int64_t pkt_pts = AV_NOPTS_VALUE;
  474. uint8_t pic_type = 0;
  475. uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) ==
  476. VDEC_FLAG_BOTTOMFIELD;
  477. uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST);
  478. int width = output->PicInfo.width;
  479. int height = output->PicInfo.height;
  480. int bwidth;
  481. uint8_t *src = output->Ybuff;
  482. int sStride;
  483. uint8_t *dst;
  484. int dStride;
  485. if (output->PicInfo.timeStamp != 0) {
  486. OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp);
  487. if (node) {
  488. pkt_pts = node->reordered_opaque;
  489. pic_type = node->pic_type;
  490. av_free(node);
  491. } else {
  492. /*
  493. * We will encounter a situation where a timestamp cannot be
  494. * popped if a second field is being returned. In this case,
  495. * each field has the same timestamp and the first one will
  496. * cause it to be popped. To keep subsequent calculations
  497. * simple, pic_type should be set a FIELD value - doesn't
  498. * matter which, but I chose BOTTOM.
  499. */
  500. pic_type = PICT_BOTTOM_FIELD;
  501. }
  502. av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n",
  503. output->PicInfo.timeStamp);
  504. av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n",
  505. pic_type);
  506. }
  507. ret = DtsGetDriverStatus(priv->dev, &decoder_status);
  508. if (ret != BC_STS_SUCCESS) {
  509. av_log(avctx, AV_LOG_ERROR,
  510. "CrystalHD: GetDriverStatus failed: %u\n", ret);
  511. return RET_ERROR;
  512. }
  513. /*
  514. * For most content, we can trust the interlaced flag returned
  515. * by the hardware, but sometimes we can't. These are the
  516. * conditions under which we can trust the flag:
  517. *
  518. * 1) It's not h.264 content
  519. * 2) The UNKNOWN_SRC flag is not set
  520. * 3) We know we're expecting a second field
  521. * 4) The hardware reports this picture and the next picture
  522. * have the same picture number.
  523. *
  524. * Note that there can still be interlaced content that will
  525. * fail this check, if the hardware hasn't decoded the next
  526. * picture or if there is a corruption in the stream. (In either
  527. * case a 0 will be returned for the next picture number)
  528. */
  529. trust_interlaced = avctx->codec->id != AV_CODEC_ID_H264 ||
  530. !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  531. priv->need_second_field ||
  532. (decoder_status.picNumFlags & ~0x40000000) ==
  533. output->PicInfo.picture_number;
  534. /*
  535. * If we got a false negative for trust_interlaced on the first field,
  536. * we will realise our mistake here when we see that the picture number is that
  537. * of the previous picture. We cannot recover the frame and should discard the
  538. * second field to keep the correct number of output frames.
  539. */
  540. if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) {
  541. av_log(avctx, AV_LOG_WARNING,
  542. "Incorrectly guessed progressive frame. Discarding second field\n");
  543. /* Returning without providing a picture. */
  544. return RET_OK;
  545. }
  546. interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) &&
  547. trust_interlaced;
  548. if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) {
  549. av_log(avctx, AV_LOG_VERBOSE,
  550. "Next picture number unknown. Assuming progressive frame.\n");
  551. }
  552. av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n",
  553. interlaced, trust_interlaced);
  554. if (priv->pic->data[0] && !priv->need_second_field)
  555. av_frame_unref(priv->pic);
  556. priv->need_second_field = interlaced && !priv->need_second_field;
  557. if (!priv->pic->data[0]) {
  558. if (ff_get_buffer(avctx, priv->pic, AV_GET_BUFFER_FLAG_REF) < 0)
  559. return RET_ERROR;
  560. }
  561. bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0);
  562. if (priv->is_70012) {
  563. int pStride;
  564. if (width <= 720)
  565. pStride = 720;
  566. else if (width <= 1280)
  567. pStride = 1280;
  568. else pStride = 1920;
  569. sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0);
  570. } else {
  571. sStride = bwidth;
  572. }
  573. dStride = priv->pic->linesize[0];
  574. dst = priv->pic->data[0];
  575. av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n");
  576. if (interlaced) {
  577. int dY = 0;
  578. int sY = 0;
  579. height /= 2;
  580. if (bottom_field) {
  581. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n");
  582. dY = 1;
  583. } else {
  584. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n");
  585. dY = 0;
  586. }
  587. for (sY = 0; sY < height; dY++, sY++) {
  588. memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth);
  589. dY++;
  590. }
  591. } else {
  592. av_image_copy_plane(dst, dStride, src, sStride, bwidth, height);
  593. }
  594. priv->pic->interlaced_frame = interlaced;
  595. if (interlaced)
  596. priv->pic->top_field_first = !bottom_first;
  597. priv->pic->pkt_pts = pkt_pts;
  598. if (!priv->need_second_field) {
  599. *got_frame = 1;
  600. if ((ret = av_frame_ref(data, priv->pic)) < 0) {
  601. return ret;
  602. }
  603. }
  604. /*
  605. * Two types of PAFF content have been observed. One form causes the
  606. * hardware to return a field pair and the other individual fields,
  607. * even though the input is always individual fields. We must skip
  608. * copying on the next decode() call to maintain pipeline length in
  609. * the first case.
  610. */
  611. if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
  612. (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
  613. av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
  614. return RET_SKIP_NEXT_COPY;
  615. }
  616. /*
  617. * The logic here is purely based on empirical testing with samples.
  618. * If we need a second field, it could come from a second input packet,
  619. * or it could come from the same field-pair input packet at the current
  620. * field. In the first case, we should return and wait for the next time
  621. * round to get the second field, while in the second case, we should
  622. * ask the decoder for it immediately.
  623. *
  624. * Testing has shown that we are dealing with the fieldpair -> two fields
  625. * case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture
  626. * type was PICT_FRAME (in this second case, the flag might still be set)
  627. */
  628. return priv->need_second_field &&
  629. (!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  630. pic_type == PICT_FRAME) ?
  631. RET_COPY_NEXT_FIELD : RET_OK;
  632. }
  633. static inline CopyRet receive_frame(AVCodecContext *avctx,
  634. void *data, int *got_frame)
  635. {
  636. BC_STATUS ret;
  637. BC_DTS_PROC_OUT output = {
  638. .PicInfo.width = avctx->width,
  639. .PicInfo.height = avctx->height,
  640. };
  641. CHDContext *priv = avctx->priv_data;
  642. HANDLE dev = priv->dev;
  643. *got_frame = 0;
  644. // Request decoded data from the driver
  645. ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);
  646. if (ret == BC_STS_FMT_CHANGE) {
  647. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n");
  648. avctx->width = output.PicInfo.width;
  649. avctx->height = output.PicInfo.height;
  650. switch ( output.PicInfo.aspect_ratio ) {
  651. case vdecAspectRatioSquare:
  652. avctx->sample_aspect_ratio = (AVRational) { 1, 1};
  653. break;
  654. case vdecAspectRatio12_11:
  655. avctx->sample_aspect_ratio = (AVRational) { 12, 11};
  656. break;
  657. case vdecAspectRatio10_11:
  658. avctx->sample_aspect_ratio = (AVRational) { 10, 11};
  659. break;
  660. case vdecAspectRatio16_11:
  661. avctx->sample_aspect_ratio = (AVRational) { 16, 11};
  662. break;
  663. case vdecAspectRatio40_33:
  664. avctx->sample_aspect_ratio = (AVRational) { 40, 33};
  665. break;
  666. case vdecAspectRatio24_11:
  667. avctx->sample_aspect_ratio = (AVRational) { 24, 11};
  668. break;
  669. case vdecAspectRatio20_11:
  670. avctx->sample_aspect_ratio = (AVRational) { 20, 11};
  671. break;
  672. case vdecAspectRatio32_11:
  673. avctx->sample_aspect_ratio = (AVRational) { 32, 11};
  674. break;
  675. case vdecAspectRatio80_33:
  676. avctx->sample_aspect_ratio = (AVRational) { 80, 33};
  677. break;
  678. case vdecAspectRatio18_11:
  679. avctx->sample_aspect_ratio = (AVRational) { 18, 11};
  680. break;
  681. case vdecAspectRatio15_11:
  682. avctx->sample_aspect_ratio = (AVRational) { 15, 11};
  683. break;
  684. case vdecAspectRatio64_33:
  685. avctx->sample_aspect_ratio = (AVRational) { 64, 33};
  686. break;
  687. case vdecAspectRatio160_99:
  688. avctx->sample_aspect_ratio = (AVRational) {160, 99};
  689. break;
  690. case vdecAspectRatio4_3:
  691. avctx->sample_aspect_ratio = (AVRational) { 4, 3};
  692. break;
  693. case vdecAspectRatio16_9:
  694. avctx->sample_aspect_ratio = (AVRational) { 16, 9};
  695. break;
  696. case vdecAspectRatio221_1:
  697. avctx->sample_aspect_ratio = (AVRational) {221, 1};
  698. break;
  699. }
  700. return RET_COPY_AGAIN;
  701. } else if (ret == BC_STS_SUCCESS) {
  702. int copy_ret = -1;
  703. if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
  704. if (priv->last_picture == -1) {
  705. /*
  706. * Init to one less, so that the incrementing code doesn't
  707. * need to be special-cased.
  708. */
  709. priv->last_picture = output.PicInfo.picture_number - 1;
  710. }
  711. if (avctx->codec->id == AV_CODEC_ID_MPEG4 &&
  712. output.PicInfo.timeStamp == 0 && priv->bframe_bug) {
  713. av_log(avctx, AV_LOG_VERBOSE,
  714. "CrystalHD: Not returning packed frame twice.\n");
  715. priv->last_picture++;
  716. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  717. return RET_COPY_AGAIN;
  718. }
  719. print_frame_info(priv, &output);
  720. if (priv->last_picture + 1 < output.PicInfo.picture_number) {
  721. av_log(avctx, AV_LOG_WARNING,
  722. "CrystalHD: Picture Number discontinuity\n");
  723. /*
  724. * Have we lost frames? If so, we need to shrink the
  725. * pipeline length appropriately.
  726. *
  727. * XXX: I have no idea what the semantics of this situation
  728. * are so I don't even know if we've lost frames or which
  729. * ones.
  730. *
  731. * In any case, only warn the first time.
  732. */
  733. priv->last_picture = output.PicInfo.picture_number - 1;
  734. }
  735. copy_ret = copy_frame(avctx, &output, data, got_frame);
  736. if (*got_frame > 0) {
  737. avctx->has_b_frames--;
  738. priv->last_picture++;
  739. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
  740. avctx->has_b_frames);
  741. }
  742. } else {
  743. /*
  744. * An invalid frame has been consumed.
  745. */
  746. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
  747. "invalid PIB\n");
  748. avctx->has_b_frames--;
  749. copy_ret = RET_OK;
  750. }
  751. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  752. return copy_ret;
  753. } else if (ret == BC_STS_BUSY) {
  754. return RET_COPY_AGAIN;
  755. } else {
  756. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
  757. return RET_ERROR;
  758. }
  759. }
  760. static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
  761. {
  762. BC_STATUS ret;
  763. BC_DTS_STATUS decoder_status = { 0, };
  764. CopyRet rec_ret;
  765. CHDContext *priv = avctx->priv_data;
  766. HANDLE dev = priv->dev;
  767. uint8_t *in_data = avpkt->data;
  768. int len = avpkt->size;
  769. int free_data = 0;
  770. uint8_t pic_type = 0;
  771. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
  772. if (avpkt->size == 7 && !priv->bframe_bug) {
  773. /*
  774. * The use of a drop frame triggers the bug
  775. */
  776. av_log(avctx, AV_LOG_INFO,
  777. "CrystalHD: Enabling work-around for packed b-frame bug\n");
  778. priv->bframe_bug = 1;
  779. } else if (avpkt->size == 8 && priv->bframe_bug) {
  780. /*
  781. * Delay frames don't trigger the bug
  782. */
  783. av_log(avctx, AV_LOG_INFO,
  784. "CrystalHD: Disabling work-around for packed b-frame bug\n");
  785. priv->bframe_bug = 0;
  786. }
  787. if (len) {
  788. int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
  789. if (priv->parser) {
  790. int ret = 0;
  791. if (priv->bsfc) {
  792. ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL,
  793. &in_data, &len,
  794. avpkt->data, len, 0);
  795. }
  796. free_data = ret > 0;
  797. if (ret >= 0) {
  798. uint8_t *pout;
  799. int psize;
  800. int index;
  801. H264Context *h = priv->parser->priv_data;
  802. index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
  803. in_data, len, avctx->internal->pkt->pts,
  804. avctx->internal->pkt->dts, 0);
  805. if (index < 0) {
  806. av_log(avctx, AV_LOG_WARNING,
  807. "CrystalHD: Failed to parse h.264 packet to "
  808. "detect interlacing.\n");
  809. } else if (index != len) {
  810. av_log(avctx, AV_LOG_WARNING,
  811. "CrystalHD: Failed to parse h.264 packet "
  812. "completely. Interlaced frames may be "
  813. "incorrectly detected.\n");
  814. } else {
  815. av_log(avctx, AV_LOG_VERBOSE,
  816. "CrystalHD: parser picture type %d\n",
  817. h->picture_structure);
  818. pic_type = h->picture_structure;
  819. }
  820. } else {
  821. av_log(avctx, AV_LOG_WARNING,
  822. "CrystalHD: mp4toannexb filter failed to filter "
  823. "packet. Interlaced frames may be incorrectly "
  824. "detected.\n");
  825. }
  826. }
  827. if (len < tx_free - 1024) {
  828. /*
  829. * Despite being notionally opaque, either libcrystalhd or
  830. * the hardware itself will mangle pts values that are too
  831. * small or too large. The docs claim it should be in units
  832. * of 100ns. Given that we're nominally dealing with a black
  833. * box on both sides, any transform we do has no guarantee of
  834. * avoiding mangling so we need to build a mapping to values
  835. * we know will not be mangled.
  836. */
  837. uint64_t pts = opaque_list_push(priv, avctx->internal->pkt->pts, pic_type);
  838. if (!pts) {
  839. if (free_data) {
  840. av_freep(&in_data);
  841. }
  842. return AVERROR(ENOMEM);
  843. }
  844. av_log(priv->avctx, AV_LOG_VERBOSE,
  845. "input \"pts\": %"PRIu64"\n", pts);
  846. ret = DtsProcInput(dev, in_data, len, pts, 0);
  847. if (free_data) {
  848. av_freep(&in_data);
  849. }
  850. if (ret == BC_STS_BUSY) {
  851. av_log(avctx, AV_LOG_WARNING,
  852. "CrystalHD: ProcInput returned busy\n");
  853. usleep(BASE_WAIT);
  854. return AVERROR(EBUSY);
  855. } else if (ret != BC_STS_SUCCESS) {
  856. av_log(avctx, AV_LOG_ERROR,
  857. "CrystalHD: ProcInput failed: %u\n", ret);
  858. return -1;
  859. }
  860. avctx->has_b_frames++;
  861. } else {
  862. av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n");
  863. len = 0; // We didn't consume any bytes.
  864. }
  865. } else {
  866. av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
  867. }
  868. if (priv->skip_next_output) {
  869. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n");
  870. priv->skip_next_output = 0;
  871. avctx->has_b_frames--;
  872. return len;
  873. }
  874. ret = DtsGetDriverStatus(dev, &decoder_status);
  875. if (ret != BC_STS_SUCCESS) {
  876. av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
  877. return -1;
  878. }
  879. /*
  880. * No frames ready. Don't try to extract.
  881. *
  882. * Empirical testing shows that ReadyListCount can be a damn lie,
  883. * and ProcOut still fails when count > 0. The same testing showed
  884. * that two more iterations were needed before ProcOutput would
  885. * succeed.
  886. */
  887. if (priv->output_ready < 2) {
  888. if (decoder_status.ReadyListCount != 0)
  889. priv->output_ready++;
  890. usleep(BASE_WAIT);
  891. av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
  892. return len;
  893. } else if (decoder_status.ReadyListCount == 0) {
  894. /*
  895. * After the pipeline is established, if we encounter a lack of frames
  896. * that probably means we're not giving the hardware enough time to
  897. * decode them, so start increasing the wait time at the end of a
  898. * decode call.
  899. */
  900. usleep(BASE_WAIT);
  901. priv->decode_wait += WAIT_UNIT;
  902. av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
  903. return len;
  904. }
  905. do {
  906. rec_ret = receive_frame(avctx, data, got_frame);
  907. if (rec_ret == RET_OK && *got_frame == 0) {
  908. /*
  909. * This case is for when the encoded fields are stored
  910. * separately and we get a separate avpkt for each one. To keep
  911. * the pipeline stable, we should return nothing and wait for
  912. * the next time round to grab the second field.
  913. * H.264 PAFF is an example of this.
  914. */
  915. av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
  916. avctx->has_b_frames--;
  917. } else if (rec_ret == RET_COPY_NEXT_FIELD) {
  918. /*
  919. * This case is for when the encoded fields are stored in a
  920. * single avpkt but the hardware returns then separately. Unless
  921. * we grab the second field before returning, we'll slip another
  922. * frame in the pipeline and if that happens a lot, we're sunk.
  923. * So we have to get that second field now.
  924. * Interlaced mpeg2 and vc1 are examples of this.
  925. */
  926. av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
  927. while (1) {
  928. usleep(priv->decode_wait);
  929. ret = DtsGetDriverStatus(dev, &decoder_status);
  930. if (ret == BC_STS_SUCCESS &&
  931. decoder_status.ReadyListCount > 0) {
  932. rec_ret = receive_frame(avctx, data, got_frame);
  933. if ((rec_ret == RET_OK && *got_frame > 0) ||
  934. rec_ret == RET_ERROR)
  935. break;
  936. }
  937. }
  938. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
  939. } else if (rec_ret == RET_SKIP_NEXT_COPY) {
  940. /*
  941. * Two input packets got turned into a field pair. Gawd.
  942. */
  943. av_log(avctx, AV_LOG_VERBOSE,
  944. "Don't output on next decode call.\n");
  945. priv->skip_next_output = 1;
  946. }
  947. /*
  948. * If rec_ret == RET_COPY_AGAIN, that means that either we just handled
  949. * a FMT_CHANGE event and need to go around again for the actual frame,
  950. * we got a busy status and need to try again, or we're dealing with
  951. * packed b-frames, where the hardware strangely returns the packed
  952. * p-frame twice. We choose to keep the second copy as it carries the
  953. * valid pts.
  954. */
  955. } while (rec_ret == RET_COPY_AGAIN);
  956. usleep(priv->decode_wait);
  957. return len;
  958. }
  959. #if CONFIG_H264_CRYSTALHD_DECODER
  960. static AVClass h264_class = {
  961. "h264_crystalhd",
  962. av_default_item_name,
  963. options,
  964. LIBAVUTIL_VERSION_INT,
  965. };
  966. AVCodec ff_h264_crystalhd_decoder = {
  967. .name = "h264_crystalhd",
  968. .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
  969. .type = AVMEDIA_TYPE_VIDEO,
  970. .id = AV_CODEC_ID_H264,
  971. .priv_data_size = sizeof(CHDContext),
  972. .init = init,
  973. .close = uninit,
  974. .decode = decode,
  975. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  976. .flush = flush,
  977. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  978. .priv_class = &h264_class,
  979. };
  980. #endif
  981. #if CONFIG_MPEG2_CRYSTALHD_DECODER
  982. static AVClass mpeg2_class = {
  983. "mpeg2_crystalhd",
  984. av_default_item_name,
  985. options,
  986. LIBAVUTIL_VERSION_INT,
  987. };
  988. AVCodec ff_mpeg2_crystalhd_decoder = {
  989. .name = "mpeg2_crystalhd",
  990. .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
  991. .type = AVMEDIA_TYPE_VIDEO,
  992. .id = AV_CODEC_ID_MPEG2VIDEO,
  993. .priv_data_size = sizeof(CHDContext),
  994. .init = init,
  995. .close = uninit,
  996. .decode = decode,
  997. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  998. .flush = flush,
  999. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1000. .priv_class = &mpeg2_class,
  1001. };
  1002. #endif
  1003. #if CONFIG_MPEG4_CRYSTALHD_DECODER
  1004. static AVClass mpeg4_class = {
  1005. "mpeg4_crystalhd",
  1006. av_default_item_name,
  1007. options,
  1008. LIBAVUTIL_VERSION_INT,
  1009. };
  1010. AVCodec ff_mpeg4_crystalhd_decoder = {
  1011. .name = "mpeg4_crystalhd",
  1012. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
  1013. .type = AVMEDIA_TYPE_VIDEO,
  1014. .id = AV_CODEC_ID_MPEG4,
  1015. .priv_data_size = sizeof(CHDContext),
  1016. .init = init,
  1017. .close = uninit,
  1018. .decode = decode,
  1019. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1020. .flush = flush,
  1021. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1022. .priv_class = &mpeg4_class,
  1023. };
  1024. #endif
  1025. #if CONFIG_MSMPEG4_CRYSTALHD_DECODER
  1026. static AVClass msmpeg4_class = {
  1027. "msmpeg4_crystalhd",
  1028. av_default_item_name,
  1029. options,
  1030. LIBAVUTIL_VERSION_INT,
  1031. };
  1032. AVCodec ff_msmpeg4_crystalhd_decoder = {
  1033. .name = "msmpeg4_crystalhd",
  1034. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
  1035. .type = AVMEDIA_TYPE_VIDEO,
  1036. .id = AV_CODEC_ID_MSMPEG4V3,
  1037. .priv_data_size = sizeof(CHDContext),
  1038. .init = init,
  1039. .close = uninit,
  1040. .decode = decode,
  1041. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
  1042. .flush = flush,
  1043. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1044. .priv_class = &msmpeg4_class,
  1045. };
  1046. #endif
  1047. #if CONFIG_VC1_CRYSTALHD_DECODER
  1048. static AVClass vc1_class = {
  1049. "vc1_crystalhd",
  1050. av_default_item_name,
  1051. options,
  1052. LIBAVUTIL_VERSION_INT,
  1053. };
  1054. AVCodec ff_vc1_crystalhd_decoder = {
  1055. .name = "vc1_crystalhd",
  1056. .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
  1057. .type = AVMEDIA_TYPE_VIDEO,
  1058. .id = AV_CODEC_ID_VC1,
  1059. .priv_data_size = sizeof(CHDContext),
  1060. .init = init,
  1061. .close = uninit,
  1062. .decode = decode,
  1063. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1064. .flush = flush,
  1065. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1066. .priv_class = &vc1_class,
  1067. };
  1068. #endif
  1069. #if CONFIG_WMV3_CRYSTALHD_DECODER
  1070. static AVClass wmv3_class = {
  1071. "wmv3_crystalhd",
  1072. av_default_item_name,
  1073. options,
  1074. LIBAVUTIL_VERSION_INT,
  1075. };
  1076. AVCodec ff_wmv3_crystalhd_decoder = {
  1077. .name = "wmv3_crystalhd",
  1078. .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
  1079. .type = AVMEDIA_TYPE_VIDEO,
  1080. .id = AV_CODEC_ID_WMV3,
  1081. .priv_data_size = sizeof(CHDContext),
  1082. .init = init,
  1083. .close = uninit,
  1084. .decode = decode,
  1085. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1086. .flush = flush,
  1087. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1088. .priv_class = &wmv3_class,
  1089. };
  1090. #endif