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.

1226 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 "libavutil/imgutils.h"
  84. #include "libavutil/intreadwrite.h"
  85. #include "libavutil/opt.h"
  86. /** Timeout parameter passed to DtsProcOutput() in us */
  87. #define OUTPUT_PROC_TIMEOUT 50
  88. /** Step between fake timestamps passed to hardware in units of 100ns */
  89. #define TIMESTAMP_UNIT 100000
  90. /** Initial value in us of the wait in decode() */
  91. #define BASE_WAIT 10000
  92. /** Increment in us to adjust wait in decode() */
  93. #define WAIT_UNIT 1000
  94. /*****************************************************************************
  95. * Module private data
  96. ****************************************************************************/
  97. typedef enum {
  98. RET_ERROR = -1,
  99. RET_OK = 0,
  100. RET_COPY_AGAIN = 1,
  101. RET_SKIP_NEXT_COPY = 2,
  102. RET_COPY_NEXT_FIELD = 3,
  103. } CopyRet;
  104. typedef struct OpaqueList {
  105. struct OpaqueList *next;
  106. uint64_t fake_timestamp;
  107. uint64_t reordered_opaque;
  108. uint8_t pic_type;
  109. } OpaqueList;
  110. typedef struct {
  111. AVClass *av_class;
  112. AVCodecContext *avctx;
  113. AVFrame pic;
  114. HANDLE dev;
  115. uint8_t *orig_extradata;
  116. uint32_t orig_extradata_size;
  117. AVBitStreamFilterContext *bsfc;
  118. AVCodecParserContext *parser;
  119. uint8_t is_70012;
  120. uint8_t *sps_pps_buf;
  121. uint32_t sps_pps_size;
  122. uint8_t is_nal;
  123. uint8_t output_ready;
  124. uint8_t need_second_field;
  125. uint8_t skip_next_output;
  126. uint64_t decode_wait;
  127. uint64_t last_picture;
  128. OpaqueList *head;
  129. OpaqueList *tail;
  130. /* Options */
  131. uint32_t sWidth;
  132. uint8_t bframe_bug;
  133. } CHDContext;
  134. static const AVOption options[] = {
  135. { "crystalhd_downscale_width",
  136. "Turn on downscaling to the specified width",
  137. offsetof(CHDContext, sWidth),
  138. AV_OPT_TYPE_INT, 0, 0, UINT32_MAX,
  139. AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, },
  140. { NULL, },
  141. };
  142. /*****************************************************************************
  143. * Helper functions
  144. ****************************************************************************/
  145. static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum AVCodecID id)
  146. {
  147. switch (id) {
  148. case AV_CODEC_ID_MPEG4:
  149. return BC_MSUBTYPE_DIVX;
  150. case AV_CODEC_ID_MSMPEG4V3:
  151. return BC_MSUBTYPE_DIVX311;
  152. case AV_CODEC_ID_MPEG2VIDEO:
  153. return BC_MSUBTYPE_MPEG2VIDEO;
  154. case AV_CODEC_ID_VC1:
  155. return BC_MSUBTYPE_VC1;
  156. case AV_CODEC_ID_WMV3:
  157. return BC_MSUBTYPE_WMV3;
  158. case AV_CODEC_ID_H264:
  159. return priv->is_nal ? BC_MSUBTYPE_AVC1 : BC_MSUBTYPE_H264;
  160. default:
  161. return BC_MSUBTYPE_INVALID;
  162. }
  163. }
  164. static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output)
  165. {
  166. av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz);
  167. av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n",
  168. output->YBuffDoneSz);
  169. av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n",
  170. output->UVBuffDoneSz);
  171. av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n",
  172. output->PicInfo.timeStamp);
  173. av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n",
  174. output->PicInfo.picture_number);
  175. av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n",
  176. output->PicInfo.width);
  177. av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n",
  178. output->PicInfo.height);
  179. av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n",
  180. output->PicInfo.chroma_format);
  181. av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n",
  182. output->PicInfo.pulldown);
  183. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n",
  184. output->PicInfo.flags);
  185. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n",
  186. output->PicInfo.frame_rate);
  187. av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n",
  188. output->PicInfo.aspect_ratio);
  189. av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n",
  190. output->PicInfo.colour_primaries);
  191. av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n",
  192. output->PicInfo.picture_meta_payload);
  193. av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n",
  194. output->PicInfo.sess_num);
  195. av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n",
  196. output->PicInfo.ycom);
  197. av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n",
  198. output->PicInfo.custom_aspect_ratio_width_height);
  199. av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n",
  200. output->PicInfo.n_drop);
  201. av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n",
  202. output->PicInfo.other.h264.valid);
  203. }
  204. /*****************************************************************************
  205. * OpaqueList functions
  206. ****************************************************************************/
  207. static uint64_t opaque_list_push(CHDContext *priv, uint64_t reordered_opaque,
  208. uint8_t pic_type)
  209. {
  210. OpaqueList *newNode = av_mallocz(sizeof (OpaqueList));
  211. if (!newNode) {
  212. av_log(priv->avctx, AV_LOG_ERROR,
  213. "Unable to allocate new node in OpaqueList.\n");
  214. return 0;
  215. }
  216. if (!priv->head) {
  217. newNode->fake_timestamp = TIMESTAMP_UNIT;
  218. priv->head = newNode;
  219. } else {
  220. newNode->fake_timestamp = priv->tail->fake_timestamp + TIMESTAMP_UNIT;
  221. priv->tail->next = newNode;
  222. }
  223. priv->tail = newNode;
  224. newNode->reordered_opaque = reordered_opaque;
  225. newNode->pic_type = pic_type;
  226. return newNode->fake_timestamp;
  227. }
  228. /*
  229. * The OpaqueList is built in decode order, while elements will be removed
  230. * in presentation order. If frames are reordered, this means we must be
  231. * able to remove elements that are not the first element.
  232. *
  233. * Returned node must be freed by caller.
  234. */
  235. static OpaqueList *opaque_list_pop(CHDContext *priv, uint64_t fake_timestamp)
  236. {
  237. OpaqueList *node = priv->head;
  238. if (!priv->head) {
  239. av_log(priv->avctx, AV_LOG_ERROR,
  240. "CrystalHD: Attempted to query non-existent timestamps.\n");
  241. return NULL;
  242. }
  243. /*
  244. * The first element is special-cased because we have to manipulate
  245. * the head pointer rather than the previous element in the list.
  246. */
  247. if (priv->head->fake_timestamp == fake_timestamp) {
  248. priv->head = node->next;
  249. if (!priv->head->next)
  250. priv->tail = priv->head;
  251. node->next = NULL;
  252. return node;
  253. }
  254. /*
  255. * The list is processed at arm's length so that we have the
  256. * previous element available to rewrite its next pointer.
  257. */
  258. while (node->next) {
  259. OpaqueList *current = node->next;
  260. if (current->fake_timestamp == fake_timestamp) {
  261. node->next = current->next;
  262. if (!node->next)
  263. priv->tail = node;
  264. current->next = NULL;
  265. return current;
  266. } else {
  267. node = current;
  268. }
  269. }
  270. av_log(priv->avctx, AV_LOG_VERBOSE,
  271. "CrystalHD: Couldn't match fake_timestamp.\n");
  272. return NULL;
  273. }
  274. /*****************************************************************************
  275. * Video decoder API function definitions
  276. ****************************************************************************/
  277. static void flush(AVCodecContext *avctx)
  278. {
  279. CHDContext *priv = avctx->priv_data;
  280. avctx->has_b_frames = 0;
  281. priv->last_picture = -1;
  282. priv->output_ready = 0;
  283. priv->need_second_field = 0;
  284. priv->skip_next_output = 0;
  285. priv->decode_wait = BASE_WAIT;
  286. if (priv->pic.data[0])
  287. avctx->release_buffer(avctx, &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. if (priv->pic.data[0])
  317. avctx->release_buffer(avctx, &priv->pic);
  318. if (priv->head) {
  319. OpaqueList *node = priv->head;
  320. while (node) {
  321. OpaqueList *next = node->next;
  322. av_free(node);
  323. node = next;
  324. }
  325. }
  326. return 0;
  327. }
  328. static av_cold int init(AVCodecContext *avctx)
  329. {
  330. CHDContext* priv;
  331. BC_STATUS ret;
  332. BC_INFO_CRYSTAL version;
  333. BC_INPUT_FORMAT format = {
  334. .FGTEnable = FALSE,
  335. .Progressive = TRUE,
  336. .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40,
  337. .width = avctx->width,
  338. .height = avctx->height,
  339. };
  340. BC_MEDIA_SUBTYPE subtype;
  341. uint32_t mode = DTS_PLAYBACK_MODE |
  342. DTS_LOAD_FILE_PLAY_FW |
  343. DTS_SKIP_TX_CHK_CPB |
  344. DTS_PLAYBACK_DROP_RPT_MODE |
  345. DTS_SINGLE_THREADED_MODE |
  346. DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976);
  347. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n",
  348. avctx->codec->name);
  349. avctx->pix_fmt = PIX_FMT_YUYV422;
  350. /* Initialize the library */
  351. priv = avctx->priv_data;
  352. priv->avctx = avctx;
  353. priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1;
  354. priv->last_picture = -1;
  355. priv->decode_wait = BASE_WAIT;
  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);
  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 *data_size)
  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. avctx->release_buffer(avctx, &priv->pic);
  556. priv->need_second_field = interlaced && !priv->need_second_field;
  557. priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
  558. FF_BUFFER_HINTS_REUSABLE;
  559. if (!priv->pic.data[0]) {
  560. if (avctx->get_buffer(avctx, &priv->pic) < 0) {
  561. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  562. return RET_ERROR;
  563. }
  564. }
  565. bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0);
  566. if (priv->is_70012) {
  567. int pStride;
  568. if (width <= 720)
  569. pStride = 720;
  570. else if (width <= 1280)
  571. pStride = 1280;
  572. else pStride = 1920;
  573. sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0);
  574. } else {
  575. sStride = bwidth;
  576. }
  577. dStride = priv->pic.linesize[0];
  578. dst = priv->pic.data[0];
  579. av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n");
  580. if (interlaced) {
  581. int dY = 0;
  582. int sY = 0;
  583. height /= 2;
  584. if (bottom_field) {
  585. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n");
  586. dY = 1;
  587. } else {
  588. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n");
  589. dY = 0;
  590. }
  591. for (sY = 0; sY < height; dY++, sY++) {
  592. memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth);
  593. dY++;
  594. }
  595. } else {
  596. av_image_copy_plane(dst, dStride, src, sStride, bwidth, height);
  597. }
  598. priv->pic.interlaced_frame = interlaced;
  599. if (interlaced)
  600. priv->pic.top_field_first = !bottom_first;
  601. priv->pic.pkt_pts = pkt_pts;
  602. if (!priv->need_second_field) {
  603. *data_size = sizeof(AVFrame);
  604. *(AVFrame *)data = priv->pic;
  605. }
  606. /*
  607. * Two types of PAFF content have been observed. One form causes the
  608. * hardware to return a field pair and the other individual fields,
  609. * even though the input is always individual fields. We must skip
  610. * copying on the next decode() call to maintain pipeline length in
  611. * the first case.
  612. */
  613. if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
  614. (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
  615. av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
  616. return RET_SKIP_NEXT_COPY;
  617. }
  618. /*
  619. * The logic here is purely based on empirical testing with samples.
  620. * If we need a second field, it could come from a second input packet,
  621. * or it could come from the same field-pair input packet at the current
  622. * field. In the first case, we should return and wait for the next time
  623. * round to get the second field, while in the second case, we should
  624. * ask the decoder for it immediately.
  625. *
  626. * Testing has shown that we are dealing with the fieldpair -> two fields
  627. * case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture
  628. * type was PICT_FRAME (in this second case, the flag might still be set)
  629. */
  630. return priv->need_second_field &&
  631. (!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  632. pic_type == PICT_FRAME) ?
  633. RET_COPY_NEXT_FIELD : RET_OK;
  634. }
  635. static inline CopyRet receive_frame(AVCodecContext *avctx,
  636. void *data, int *data_size)
  637. {
  638. BC_STATUS ret;
  639. BC_DTS_PROC_OUT output = {
  640. .PicInfo.width = avctx->width,
  641. .PicInfo.height = avctx->height,
  642. };
  643. CHDContext *priv = avctx->priv_data;
  644. HANDLE dev = priv->dev;
  645. *data_size = 0;
  646. // Request decoded data from the driver
  647. ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);
  648. if (ret == BC_STS_FMT_CHANGE) {
  649. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n");
  650. avctx->width = output.PicInfo.width;
  651. avctx->height = output.PicInfo.height;
  652. switch ( output.PicInfo.aspect_ratio ) {
  653. case vdecAspectRatioSquare:
  654. avctx->sample_aspect_ratio = (AVRational) { 1, 1};
  655. break;
  656. case vdecAspectRatio12_11:
  657. avctx->sample_aspect_ratio = (AVRational) { 12, 11};
  658. break;
  659. case vdecAspectRatio10_11:
  660. avctx->sample_aspect_ratio = (AVRational) { 10, 11};
  661. break;
  662. case vdecAspectRatio16_11:
  663. avctx->sample_aspect_ratio = (AVRational) { 16, 11};
  664. break;
  665. case vdecAspectRatio40_33:
  666. avctx->sample_aspect_ratio = (AVRational) { 40, 33};
  667. break;
  668. case vdecAspectRatio24_11:
  669. avctx->sample_aspect_ratio = (AVRational) { 24, 11};
  670. break;
  671. case vdecAspectRatio20_11:
  672. avctx->sample_aspect_ratio = (AVRational) { 20, 11};
  673. break;
  674. case vdecAspectRatio32_11:
  675. avctx->sample_aspect_ratio = (AVRational) { 32, 11};
  676. break;
  677. case vdecAspectRatio80_33:
  678. avctx->sample_aspect_ratio = (AVRational) { 80, 33};
  679. break;
  680. case vdecAspectRatio18_11:
  681. avctx->sample_aspect_ratio = (AVRational) { 18, 11};
  682. break;
  683. case vdecAspectRatio15_11:
  684. avctx->sample_aspect_ratio = (AVRational) { 15, 11};
  685. break;
  686. case vdecAspectRatio64_33:
  687. avctx->sample_aspect_ratio = (AVRational) { 64, 33};
  688. break;
  689. case vdecAspectRatio160_99:
  690. avctx->sample_aspect_ratio = (AVRational) {160, 99};
  691. break;
  692. case vdecAspectRatio4_3:
  693. avctx->sample_aspect_ratio = (AVRational) { 4, 3};
  694. break;
  695. case vdecAspectRatio16_9:
  696. avctx->sample_aspect_ratio = (AVRational) { 16, 9};
  697. break;
  698. case vdecAspectRatio221_1:
  699. avctx->sample_aspect_ratio = (AVRational) {221, 1};
  700. break;
  701. }
  702. return RET_COPY_AGAIN;
  703. } else if (ret == BC_STS_SUCCESS) {
  704. int copy_ret = -1;
  705. if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
  706. if (priv->last_picture == -1) {
  707. /*
  708. * Init to one less, so that the incrementing code doesn't
  709. * need to be special-cased.
  710. */
  711. priv->last_picture = output.PicInfo.picture_number - 1;
  712. }
  713. if (avctx->codec->id == AV_CODEC_ID_MPEG4 &&
  714. output.PicInfo.timeStamp == 0 && priv->bframe_bug) {
  715. av_log(avctx, AV_LOG_VERBOSE,
  716. "CrystalHD: Not returning packed frame twice.\n");
  717. priv->last_picture++;
  718. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  719. return RET_COPY_AGAIN;
  720. }
  721. print_frame_info(priv, &output);
  722. if (priv->last_picture + 1 < output.PicInfo.picture_number) {
  723. av_log(avctx, AV_LOG_WARNING,
  724. "CrystalHD: Picture Number discontinuity\n");
  725. /*
  726. * Have we lost frames? If so, we need to shrink the
  727. * pipeline length appropriately.
  728. *
  729. * XXX: I have no idea what the semantics of this situation
  730. * are so I don't even know if we've lost frames or which
  731. * ones.
  732. *
  733. * In any case, only warn the first time.
  734. */
  735. priv->last_picture = output.PicInfo.picture_number - 1;
  736. }
  737. copy_ret = copy_frame(avctx, &output, data, data_size);
  738. if (*data_size > 0) {
  739. avctx->has_b_frames--;
  740. priv->last_picture++;
  741. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
  742. avctx->has_b_frames);
  743. }
  744. } else {
  745. /*
  746. * An invalid frame has been consumed.
  747. */
  748. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
  749. "invalid PIB\n");
  750. avctx->has_b_frames--;
  751. copy_ret = RET_OK;
  752. }
  753. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  754. return copy_ret;
  755. } else if (ret == BC_STS_BUSY) {
  756. return RET_COPY_AGAIN;
  757. } else {
  758. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
  759. return RET_ERROR;
  760. }
  761. }
  762. static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
  763. {
  764. BC_STATUS ret;
  765. BC_DTS_STATUS decoder_status = { 0, };
  766. CopyRet rec_ret;
  767. CHDContext *priv = avctx->priv_data;
  768. HANDLE dev = priv->dev;
  769. uint8_t *in_data = avpkt->data;
  770. int len = avpkt->size;
  771. int free_data = 0;
  772. uint8_t pic_type = 0;
  773. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
  774. if (avpkt->size == 7 && !priv->bframe_bug) {
  775. /*
  776. * The use of a drop frame triggers the bug
  777. */
  778. av_log(avctx, AV_LOG_INFO,
  779. "CrystalHD: Enabling work-around for packed b-frame bug\n");
  780. priv->bframe_bug = 1;
  781. } else if (avpkt->size == 8 && priv->bframe_bug) {
  782. /*
  783. * Delay frames don't trigger the bug
  784. */
  785. av_log(avctx, AV_LOG_INFO,
  786. "CrystalHD: Disabling work-around for packed b-frame bug\n");
  787. priv->bframe_bug = 0;
  788. }
  789. if (len) {
  790. int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
  791. if (priv->parser) {
  792. int ret = 0;
  793. if (priv->bsfc) {
  794. ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL,
  795. &in_data, &len,
  796. avpkt->data, len, 0);
  797. }
  798. free_data = ret > 0;
  799. if (ret >= 0) {
  800. uint8_t *pout;
  801. int psize;
  802. int index;
  803. H264Context *h = priv->parser->priv_data;
  804. index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
  805. in_data, len, avctx->pkt->pts,
  806. avctx->pkt->dts, 0);
  807. if (index < 0) {
  808. av_log(avctx, AV_LOG_WARNING,
  809. "CrystalHD: Failed to parse h.264 packet to "
  810. "detect interlacing.\n");
  811. } else if (index != len) {
  812. av_log(avctx, AV_LOG_WARNING,
  813. "CrystalHD: Failed to parse h.264 packet "
  814. "completely. Interlaced frames may be "
  815. "incorrectly detected.\n");
  816. } else {
  817. av_log(avctx, AV_LOG_VERBOSE,
  818. "CrystalHD: parser picture type %d\n",
  819. h->s.picture_structure);
  820. pic_type = h->s.picture_structure;
  821. }
  822. } else {
  823. av_log(avctx, AV_LOG_WARNING,
  824. "CrystalHD: mp4toannexb filter failed to filter "
  825. "packet. Interlaced frames may be incorrectly "
  826. "detected.\n");
  827. }
  828. }
  829. if (len < tx_free - 1024) {
  830. /*
  831. * Despite being notionally opaque, either libcrystalhd or
  832. * the hardware itself will mangle pts values that are too
  833. * small or too large. The docs claim it should be in units
  834. * of 100ns. Given that we're nominally dealing with a black
  835. * box on both sides, any transform we do has no guarantee of
  836. * avoiding mangling so we need to build a mapping to values
  837. * we know will not be mangled.
  838. */
  839. uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type);
  840. if (!pts) {
  841. if (free_data) {
  842. av_freep(&in_data);
  843. }
  844. return AVERROR(ENOMEM);
  845. }
  846. av_log(priv->avctx, AV_LOG_VERBOSE,
  847. "input \"pts\": %"PRIu64"\n", pts);
  848. ret = DtsProcInput(dev, in_data, len, pts, 0);
  849. if (free_data) {
  850. av_freep(&in_data);
  851. }
  852. if (ret == BC_STS_BUSY) {
  853. av_log(avctx, AV_LOG_WARNING,
  854. "CrystalHD: ProcInput returned busy\n");
  855. usleep(BASE_WAIT);
  856. return AVERROR(EBUSY);
  857. } else if (ret != BC_STS_SUCCESS) {
  858. av_log(avctx, AV_LOG_ERROR,
  859. "CrystalHD: ProcInput failed: %u\n", ret);
  860. return -1;
  861. }
  862. avctx->has_b_frames++;
  863. } else {
  864. av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n");
  865. len = 0; // We didn't consume any bytes.
  866. }
  867. } else {
  868. av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
  869. }
  870. if (priv->skip_next_output) {
  871. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n");
  872. priv->skip_next_output = 0;
  873. avctx->has_b_frames--;
  874. return len;
  875. }
  876. ret = DtsGetDriverStatus(dev, &decoder_status);
  877. if (ret != BC_STS_SUCCESS) {
  878. av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
  879. return -1;
  880. }
  881. /*
  882. * No frames ready. Don't try to extract.
  883. *
  884. * Empirical testing shows that ReadyListCount can be a damn lie,
  885. * and ProcOut still fails when count > 0. The same testing showed
  886. * that two more iterations were needed before ProcOutput would
  887. * succeed.
  888. */
  889. if (priv->output_ready < 2) {
  890. if (decoder_status.ReadyListCount != 0)
  891. priv->output_ready++;
  892. usleep(BASE_WAIT);
  893. av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
  894. return len;
  895. } else if (decoder_status.ReadyListCount == 0) {
  896. /*
  897. * After the pipeline is established, if we encounter a lack of frames
  898. * that probably means we're not giving the hardware enough time to
  899. * decode them, so start increasing the wait time at the end of a
  900. * decode call.
  901. */
  902. usleep(BASE_WAIT);
  903. priv->decode_wait += WAIT_UNIT;
  904. av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
  905. return len;
  906. }
  907. do {
  908. rec_ret = receive_frame(avctx, data, data_size);
  909. if (rec_ret == RET_OK && *data_size == 0) {
  910. /*
  911. * This case is for when the encoded fields are stored
  912. * separately and we get a separate avpkt for each one. To keep
  913. * the pipeline stable, we should return nothing and wait for
  914. * the next time round to grab the second field.
  915. * H.264 PAFF is an example of this.
  916. */
  917. av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
  918. avctx->has_b_frames--;
  919. } else if (rec_ret == RET_COPY_NEXT_FIELD) {
  920. /*
  921. * This case is for when the encoded fields are stored in a
  922. * single avpkt but the hardware returns then separately. Unless
  923. * we grab the second field before returning, we'll slip another
  924. * frame in the pipeline and if that happens a lot, we're sunk.
  925. * So we have to get that second field now.
  926. * Interlaced mpeg2 and vc1 are examples of this.
  927. */
  928. av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
  929. while (1) {
  930. usleep(priv->decode_wait);
  931. ret = DtsGetDriverStatus(dev, &decoder_status);
  932. if (ret == BC_STS_SUCCESS &&
  933. decoder_status.ReadyListCount > 0) {
  934. rec_ret = receive_frame(avctx, data, data_size);
  935. if ((rec_ret == RET_OK && *data_size > 0) ||
  936. rec_ret == RET_ERROR)
  937. break;
  938. }
  939. }
  940. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
  941. } else if (rec_ret == RET_SKIP_NEXT_COPY) {
  942. /*
  943. * Two input packets got turned into a field pair. Gawd.
  944. */
  945. av_log(avctx, AV_LOG_VERBOSE,
  946. "Don't output on next decode call.\n");
  947. priv->skip_next_output = 1;
  948. }
  949. /*
  950. * If rec_ret == RET_COPY_AGAIN, that means that either we just handled
  951. * a FMT_CHANGE event and need to go around again for the actual frame,
  952. * we got a busy status and need to try again, or we're dealing with
  953. * packed b-frames, where the hardware strangely returns the packed
  954. * p-frame twice. We choose to keep the second copy as it carries the
  955. * valid pts.
  956. */
  957. } while (rec_ret == RET_COPY_AGAIN);
  958. usleep(priv->decode_wait);
  959. return len;
  960. }
  961. #if CONFIG_H264_CRYSTALHD_DECODER
  962. static AVClass h264_class = {
  963. "h264_crystalhd",
  964. av_default_item_name,
  965. options,
  966. LIBAVUTIL_VERSION_INT,
  967. };
  968. AVCodec ff_h264_crystalhd_decoder = {
  969. .name = "h264_crystalhd",
  970. .type = AVMEDIA_TYPE_VIDEO,
  971. .id = AV_CODEC_ID_H264,
  972. .priv_data_size = sizeof(CHDContext),
  973. .init = init,
  974. .close = uninit,
  975. .decode = decode,
  976. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  977. .flush = flush,
  978. .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
  979. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  980. .priv_class = &h264_class,
  981. };
  982. #endif
  983. #if CONFIG_MPEG2_CRYSTALHD_DECODER
  984. static AVClass mpeg2_class = {
  985. "mpeg2_crystalhd",
  986. av_default_item_name,
  987. options,
  988. LIBAVUTIL_VERSION_INT,
  989. };
  990. AVCodec ff_mpeg2_crystalhd_decoder = {
  991. .name = "mpeg2_crystalhd",
  992. .type = AVMEDIA_TYPE_VIDEO,
  993. .id = AV_CODEC_ID_MPEG2VIDEO,
  994. .priv_data_size = sizeof(CHDContext),
  995. .init = init,
  996. .close = uninit,
  997. .decode = decode,
  998. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  999. .flush = flush,
  1000. .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
  1001. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  1002. .priv_class = &mpeg2_class,
  1003. };
  1004. #endif
  1005. #if CONFIG_MPEG4_CRYSTALHD_DECODER
  1006. static AVClass mpeg4_class = {
  1007. "mpeg4_crystalhd",
  1008. av_default_item_name,
  1009. options,
  1010. LIBAVUTIL_VERSION_INT,
  1011. };
  1012. AVCodec ff_mpeg4_crystalhd_decoder = {
  1013. .name = "mpeg4_crystalhd",
  1014. .type = AVMEDIA_TYPE_VIDEO,
  1015. .id = AV_CODEC_ID_MPEG4,
  1016. .priv_data_size = sizeof(CHDContext),
  1017. .init = init,
  1018. .close = uninit,
  1019. .decode = decode,
  1020. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1021. .flush = flush,
  1022. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
  1023. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  1024. .priv_class = &mpeg4_class,
  1025. };
  1026. #endif
  1027. #if CONFIG_MSMPEG4_CRYSTALHD_DECODER
  1028. static AVClass msmpeg4_class = {
  1029. "msmpeg4_crystalhd",
  1030. av_default_item_name,
  1031. options,
  1032. LIBAVUTIL_VERSION_INT,
  1033. };
  1034. AVCodec ff_msmpeg4_crystalhd_decoder = {
  1035. .name = "msmpeg4_crystalhd",
  1036. .type = AVMEDIA_TYPE_VIDEO,
  1037. .id = AV_CODEC_ID_MSMPEG4V3,
  1038. .priv_data_size = sizeof(CHDContext),
  1039. .init = init,
  1040. .close = uninit,
  1041. .decode = decode,
  1042. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
  1043. .flush = flush,
  1044. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
  1045. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  1046. .priv_class = &msmpeg4_class,
  1047. };
  1048. #endif
  1049. #if CONFIG_VC1_CRYSTALHD_DECODER
  1050. static AVClass vc1_class = {
  1051. "vc1_crystalhd",
  1052. av_default_item_name,
  1053. options,
  1054. LIBAVUTIL_VERSION_INT,
  1055. };
  1056. AVCodec ff_vc1_crystalhd_decoder = {
  1057. .name = "vc1_crystalhd",
  1058. .type = AVMEDIA_TYPE_VIDEO,
  1059. .id = AV_CODEC_ID_VC1,
  1060. .priv_data_size = sizeof(CHDContext),
  1061. .init = init,
  1062. .close = uninit,
  1063. .decode = decode,
  1064. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1065. .flush = flush,
  1066. .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
  1067. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  1068. .priv_class = &vc1_class,
  1069. };
  1070. #endif
  1071. #if CONFIG_WMV3_CRYSTALHD_DECODER
  1072. static AVClass wmv3_class = {
  1073. "wmv3_crystalhd",
  1074. av_default_item_name,
  1075. options,
  1076. LIBAVUTIL_VERSION_INT,
  1077. };
  1078. AVCodec ff_wmv3_crystalhd_decoder = {
  1079. .name = "wmv3_crystalhd",
  1080. .type = AVMEDIA_TYPE_VIDEO,
  1081. .id = AV_CODEC_ID_WMV3,
  1082. .priv_data_size = sizeof(CHDContext),
  1083. .init = init,
  1084. .close = uninit,
  1085. .decode = decode,
  1086. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1087. .flush = flush,
  1088. .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
  1089. .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE},
  1090. .priv_class = &wmv3_class,
  1091. };
  1092. #endif