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.

1227 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. if (priv->pic.data[0])
  288. avctx->release_buffer(avctx, &priv->pic);
  289. /* Flush mode 4 flushes all software and hardware buffers. */
  290. DtsFlushInput(priv->dev, 4);
  291. }
  292. static av_cold int uninit(AVCodecContext *avctx)
  293. {
  294. CHDContext *priv = avctx->priv_data;
  295. HANDLE device;
  296. device = priv->dev;
  297. DtsStopDecoder(device);
  298. DtsCloseDecoder(device);
  299. DtsDeviceClose(device);
  300. /*
  301. * Restore original extradata, so that if the decoder is
  302. * reinitialised, the bitstream detection and filtering
  303. * will work as expected.
  304. */
  305. if (priv->orig_extradata) {
  306. av_free(avctx->extradata);
  307. avctx->extradata = priv->orig_extradata;
  308. avctx->extradata_size = priv->orig_extradata_size;
  309. priv->orig_extradata = NULL;
  310. priv->orig_extradata_size = 0;
  311. }
  312. av_parser_close(priv->parser);
  313. if (priv->bsfc) {
  314. av_bitstream_filter_close(priv->bsfc);
  315. }
  316. av_free(priv->sps_pps_buf);
  317. if (priv->pic.data[0])
  318. avctx->release_buffer(avctx, &priv->pic);
  319. if (priv->head) {
  320. OpaqueList *node = priv->head;
  321. while (node) {
  322. OpaqueList *next = node->next;
  323. av_free(node);
  324. node = next;
  325. }
  326. }
  327. return 0;
  328. }
  329. static av_cold int init(AVCodecContext *avctx)
  330. {
  331. CHDContext* priv;
  332. BC_STATUS ret;
  333. BC_INFO_CRYSTAL version;
  334. BC_INPUT_FORMAT format = {
  335. .FGTEnable = FALSE,
  336. .Progressive = TRUE,
  337. .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40,
  338. .width = avctx->width,
  339. .height = avctx->height,
  340. };
  341. BC_MEDIA_SUBTYPE subtype;
  342. uint32_t mode = DTS_PLAYBACK_MODE |
  343. DTS_LOAD_FILE_PLAY_FW |
  344. DTS_SKIP_TX_CHK_CPB |
  345. DTS_PLAYBACK_DROP_RPT_MODE |
  346. DTS_SINGLE_THREADED_MODE |
  347. DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976);
  348. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n",
  349. avctx->codec->name);
  350. avctx->pix_fmt = AV_PIX_FMT_YUYV422;
  351. /* Initialize the library */
  352. priv = avctx->priv_data;
  353. priv->avctx = avctx;
  354. priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1;
  355. priv->last_picture = -1;
  356. priv->decode_wait = BASE_WAIT;
  357. subtype = id2subtype(priv, avctx->codec->id);
  358. switch (subtype) {
  359. case BC_MSUBTYPE_AVC1:
  360. {
  361. uint8_t *dummy_p;
  362. int dummy_int;
  363. /* Back up the extradata so it can be restored at close time. */
  364. priv->orig_extradata = av_malloc(avctx->extradata_size);
  365. if (!priv->orig_extradata) {
  366. av_log(avctx, AV_LOG_ERROR,
  367. "Failed to allocate copy of extradata\n");
  368. return AVERROR(ENOMEM);
  369. }
  370. priv->orig_extradata_size = avctx->extradata_size;
  371. memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size);
  372. priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
  373. if (!priv->bsfc) {
  374. av_log(avctx, AV_LOG_ERROR,
  375. "Cannot open the h264_mp4toannexb BSF!\n");
  376. return AVERROR_BSF_NOT_FOUND;
  377. }
  378. av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p,
  379. &dummy_int, NULL, 0, 0);
  380. }
  381. subtype = BC_MSUBTYPE_H264;
  382. // Fall-through
  383. case BC_MSUBTYPE_H264:
  384. format.startCodeSz = 4;
  385. // Fall-through
  386. case BC_MSUBTYPE_VC1:
  387. case BC_MSUBTYPE_WVC1:
  388. case BC_MSUBTYPE_WMV3:
  389. case BC_MSUBTYPE_WMVA:
  390. case BC_MSUBTYPE_MPEG2VIDEO:
  391. case BC_MSUBTYPE_DIVX:
  392. case BC_MSUBTYPE_DIVX311:
  393. format.pMetaData = avctx->extradata;
  394. format.metaDataSz = avctx->extradata_size;
  395. break;
  396. default:
  397. av_log(avctx, AV_LOG_ERROR, "CrystalHD: Unknown codec name\n");
  398. return AVERROR(EINVAL);
  399. }
  400. format.mSubtype = subtype;
  401. if (priv->sWidth) {
  402. format.bEnableScaling = 1;
  403. format.ScalingParams.sWidth = priv->sWidth;
  404. }
  405. /* Get a decoder instance */
  406. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: starting up\n");
  407. // Initialize the Link and Decoder devices
  408. ret = DtsDeviceOpen(&priv->dev, mode);
  409. if (ret != BC_STS_SUCCESS) {
  410. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: DtsDeviceOpen failed\n");
  411. goto fail;
  412. }
  413. ret = DtsCrystalHDVersion(priv->dev, &version);
  414. if (ret != BC_STS_SUCCESS) {
  415. av_log(avctx, AV_LOG_VERBOSE,
  416. "CrystalHD: DtsCrystalHDVersion failed\n");
  417. goto fail;
  418. }
  419. priv->is_70012 = version.device == 0;
  420. if (priv->is_70012 &&
  421. (subtype == BC_MSUBTYPE_DIVX || subtype == BC_MSUBTYPE_DIVX311)) {
  422. av_log(avctx, AV_LOG_VERBOSE,
  423. "CrystalHD: BCM70012 doesn't support MPEG4-ASP/DivX/Xvid\n");
  424. goto fail;
  425. }
  426. ret = DtsSetInputFormat(priv->dev, &format);
  427. if (ret != BC_STS_SUCCESS) {
  428. av_log(avctx, AV_LOG_ERROR, "CrystalHD: SetInputFormat failed\n");
  429. goto fail;
  430. }
  431. ret = DtsOpenDecoder(priv->dev, BC_STREAM_TYPE_ES);
  432. if (ret != BC_STS_SUCCESS) {
  433. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsOpenDecoder failed\n");
  434. goto fail;
  435. }
  436. ret = DtsSetColorSpace(priv->dev, OUTPUT_MODE422_YUY2);
  437. if (ret != BC_STS_SUCCESS) {
  438. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsSetColorSpace failed\n");
  439. goto fail;
  440. }
  441. ret = DtsStartDecoder(priv->dev);
  442. if (ret != BC_STS_SUCCESS) {
  443. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartDecoder failed\n");
  444. goto fail;
  445. }
  446. ret = DtsStartCapture(priv->dev);
  447. if (ret != BC_STS_SUCCESS) {
  448. av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartCapture failed\n");
  449. goto fail;
  450. }
  451. if (avctx->codec->id == AV_CODEC_ID_H264) {
  452. priv->parser = av_parser_init(avctx->codec->id);
  453. if (!priv->parser)
  454. av_log(avctx, AV_LOG_WARNING,
  455. "Cannot open the h.264 parser! Interlaced h.264 content "
  456. "will not be detected reliably.\n");
  457. priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES;
  458. }
  459. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n");
  460. return 0;
  461. fail:
  462. uninit(avctx);
  463. return -1;
  464. }
  465. static inline CopyRet copy_frame(AVCodecContext *avctx,
  466. BC_DTS_PROC_OUT *output,
  467. void *data, int *got_frame)
  468. {
  469. BC_STATUS ret;
  470. BC_DTS_STATUS decoder_status = { 0, };
  471. uint8_t trust_interlaced;
  472. uint8_t interlaced;
  473. CHDContext *priv = avctx->priv_data;
  474. int64_t pkt_pts = AV_NOPTS_VALUE;
  475. uint8_t pic_type = 0;
  476. uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) ==
  477. VDEC_FLAG_BOTTOMFIELD;
  478. uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST);
  479. int width = output->PicInfo.width;
  480. int height = output->PicInfo.height;
  481. int bwidth;
  482. uint8_t *src = output->Ybuff;
  483. int sStride;
  484. uint8_t *dst;
  485. int dStride;
  486. if (output->PicInfo.timeStamp != 0) {
  487. OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp);
  488. if (node) {
  489. pkt_pts = node->reordered_opaque;
  490. pic_type = node->pic_type;
  491. av_free(node);
  492. } else {
  493. /*
  494. * We will encounter a situation where a timestamp cannot be
  495. * popped if a second field is being returned. In this case,
  496. * each field has the same timestamp and the first one will
  497. * cause it to be popped. To keep subsequent calculations
  498. * simple, pic_type should be set a FIELD value - doesn't
  499. * matter which, but I chose BOTTOM.
  500. */
  501. pic_type = PICT_BOTTOM_FIELD;
  502. }
  503. av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n",
  504. output->PicInfo.timeStamp);
  505. av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n",
  506. pic_type);
  507. }
  508. ret = DtsGetDriverStatus(priv->dev, &decoder_status);
  509. if (ret != BC_STS_SUCCESS) {
  510. av_log(avctx, AV_LOG_ERROR,
  511. "CrystalHD: GetDriverStatus failed: %u\n", ret);
  512. return RET_ERROR;
  513. }
  514. /*
  515. * For most content, we can trust the interlaced flag returned
  516. * by the hardware, but sometimes we can't. These are the
  517. * conditions under which we can trust the flag:
  518. *
  519. * 1) It's not h.264 content
  520. * 2) The UNKNOWN_SRC flag is not set
  521. * 3) We know we're expecting a second field
  522. * 4) The hardware reports this picture and the next picture
  523. * have the same picture number.
  524. *
  525. * Note that there can still be interlaced content that will
  526. * fail this check, if the hardware hasn't decoded the next
  527. * picture or if there is a corruption in the stream. (In either
  528. * case a 0 will be returned for the next picture number)
  529. */
  530. trust_interlaced = avctx->codec->id != AV_CODEC_ID_H264 ||
  531. !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  532. priv->need_second_field ||
  533. (decoder_status.picNumFlags & ~0x40000000) ==
  534. output->PicInfo.picture_number;
  535. /*
  536. * If we got a false negative for trust_interlaced on the first field,
  537. * we will realise our mistake here when we see that the picture number is that
  538. * of the previous picture. We cannot recover the frame and should discard the
  539. * second field to keep the correct number of output frames.
  540. */
  541. if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) {
  542. av_log(avctx, AV_LOG_WARNING,
  543. "Incorrectly guessed progressive frame. Discarding second field\n");
  544. /* Returning without providing a picture. */
  545. return RET_OK;
  546. }
  547. interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) &&
  548. trust_interlaced;
  549. if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) {
  550. av_log(avctx, AV_LOG_VERBOSE,
  551. "Next picture number unknown. Assuming progressive frame.\n");
  552. }
  553. av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n",
  554. interlaced, trust_interlaced);
  555. if (priv->pic.data[0] && !priv->need_second_field)
  556. avctx->release_buffer(avctx, &priv->pic);
  557. priv->need_second_field = interlaced && !priv->need_second_field;
  558. priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
  559. FF_BUFFER_HINTS_REUSABLE;
  560. if (!priv->pic.data[0]) {
  561. if (ff_get_buffer(avctx, &priv->pic) < 0) {
  562. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  563. return RET_ERROR;
  564. }
  565. }
  566. bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0);
  567. if (priv->is_70012) {
  568. int pStride;
  569. if (width <= 720)
  570. pStride = 720;
  571. else if (width <= 1280)
  572. pStride = 1280;
  573. else pStride = 1920;
  574. sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0);
  575. } else {
  576. sStride = bwidth;
  577. }
  578. dStride = priv->pic.linesize[0];
  579. dst = priv->pic.data[0];
  580. av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n");
  581. if (interlaced) {
  582. int dY = 0;
  583. int sY = 0;
  584. height /= 2;
  585. if (bottom_field) {
  586. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n");
  587. dY = 1;
  588. } else {
  589. av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n");
  590. dY = 0;
  591. }
  592. for (sY = 0; sY < height; dY++, sY++) {
  593. memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth);
  594. dY++;
  595. }
  596. } else {
  597. av_image_copy_plane(dst, dStride, src, sStride, bwidth, height);
  598. }
  599. priv->pic.interlaced_frame = interlaced;
  600. if (interlaced)
  601. priv->pic.top_field_first = !bottom_first;
  602. priv->pic.pkt_pts = pkt_pts;
  603. if (!priv->need_second_field) {
  604. *got_frame = 1;
  605. *(AVFrame *)data = priv->pic;
  606. }
  607. /*
  608. * Two types of PAFF content have been observed. One form causes the
  609. * hardware to return a field pair and the other individual fields,
  610. * even though the input is always individual fields. We must skip
  611. * copying on the next decode() call to maintain pipeline length in
  612. * the first case.
  613. */
  614. if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
  615. (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
  616. av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
  617. return RET_SKIP_NEXT_COPY;
  618. }
  619. /*
  620. * The logic here is purely based on empirical testing with samples.
  621. * If we need a second field, it could come from a second input packet,
  622. * or it could come from the same field-pair input packet at the current
  623. * field. In the first case, we should return and wait for the next time
  624. * round to get the second field, while in the second case, we should
  625. * ask the decoder for it immediately.
  626. *
  627. * Testing has shown that we are dealing with the fieldpair -> two fields
  628. * case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture
  629. * type was PICT_FRAME (in this second case, the flag might still be set)
  630. */
  631. return priv->need_second_field &&
  632. (!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  633. pic_type == PICT_FRAME) ?
  634. RET_COPY_NEXT_FIELD : RET_OK;
  635. }
  636. static inline CopyRet receive_frame(AVCodecContext *avctx,
  637. void *data, int *got_frame)
  638. {
  639. BC_STATUS ret;
  640. BC_DTS_PROC_OUT output = {
  641. .PicInfo.width = avctx->width,
  642. .PicInfo.height = avctx->height,
  643. };
  644. CHDContext *priv = avctx->priv_data;
  645. HANDLE dev = priv->dev;
  646. *got_frame = 0;
  647. // Request decoded data from the driver
  648. ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);
  649. if (ret == BC_STS_FMT_CHANGE) {
  650. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n");
  651. avctx->width = output.PicInfo.width;
  652. avctx->height = output.PicInfo.height;
  653. switch ( output.PicInfo.aspect_ratio ) {
  654. case vdecAspectRatioSquare:
  655. avctx->sample_aspect_ratio = (AVRational) { 1, 1};
  656. break;
  657. case vdecAspectRatio12_11:
  658. avctx->sample_aspect_ratio = (AVRational) { 12, 11};
  659. break;
  660. case vdecAspectRatio10_11:
  661. avctx->sample_aspect_ratio = (AVRational) { 10, 11};
  662. break;
  663. case vdecAspectRatio16_11:
  664. avctx->sample_aspect_ratio = (AVRational) { 16, 11};
  665. break;
  666. case vdecAspectRatio40_33:
  667. avctx->sample_aspect_ratio = (AVRational) { 40, 33};
  668. break;
  669. case vdecAspectRatio24_11:
  670. avctx->sample_aspect_ratio = (AVRational) { 24, 11};
  671. break;
  672. case vdecAspectRatio20_11:
  673. avctx->sample_aspect_ratio = (AVRational) { 20, 11};
  674. break;
  675. case vdecAspectRatio32_11:
  676. avctx->sample_aspect_ratio = (AVRational) { 32, 11};
  677. break;
  678. case vdecAspectRatio80_33:
  679. avctx->sample_aspect_ratio = (AVRational) { 80, 33};
  680. break;
  681. case vdecAspectRatio18_11:
  682. avctx->sample_aspect_ratio = (AVRational) { 18, 11};
  683. break;
  684. case vdecAspectRatio15_11:
  685. avctx->sample_aspect_ratio = (AVRational) { 15, 11};
  686. break;
  687. case vdecAspectRatio64_33:
  688. avctx->sample_aspect_ratio = (AVRational) { 64, 33};
  689. break;
  690. case vdecAspectRatio160_99:
  691. avctx->sample_aspect_ratio = (AVRational) {160, 99};
  692. break;
  693. case vdecAspectRatio4_3:
  694. avctx->sample_aspect_ratio = (AVRational) { 4, 3};
  695. break;
  696. case vdecAspectRatio16_9:
  697. avctx->sample_aspect_ratio = (AVRational) { 16, 9};
  698. break;
  699. case vdecAspectRatio221_1:
  700. avctx->sample_aspect_ratio = (AVRational) {221, 1};
  701. break;
  702. }
  703. return RET_COPY_AGAIN;
  704. } else if (ret == BC_STS_SUCCESS) {
  705. int copy_ret = -1;
  706. if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
  707. if (priv->last_picture == -1) {
  708. /*
  709. * Init to one less, so that the incrementing code doesn't
  710. * need to be special-cased.
  711. */
  712. priv->last_picture = output.PicInfo.picture_number - 1;
  713. }
  714. if (avctx->codec->id == AV_CODEC_ID_MPEG4 &&
  715. output.PicInfo.timeStamp == 0 && priv->bframe_bug) {
  716. av_log(avctx, AV_LOG_VERBOSE,
  717. "CrystalHD: Not returning packed frame twice.\n");
  718. priv->last_picture++;
  719. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  720. return RET_COPY_AGAIN;
  721. }
  722. print_frame_info(priv, &output);
  723. if (priv->last_picture + 1 < output.PicInfo.picture_number) {
  724. av_log(avctx, AV_LOG_WARNING,
  725. "CrystalHD: Picture Number discontinuity\n");
  726. /*
  727. * Have we lost frames? If so, we need to shrink the
  728. * pipeline length appropriately.
  729. *
  730. * XXX: I have no idea what the semantics of this situation
  731. * are so I don't even know if we've lost frames or which
  732. * ones.
  733. *
  734. * In any case, only warn the first time.
  735. */
  736. priv->last_picture = output.PicInfo.picture_number - 1;
  737. }
  738. copy_ret = copy_frame(avctx, &output, data, got_frame);
  739. if (*got_frame > 0) {
  740. avctx->has_b_frames--;
  741. priv->last_picture++;
  742. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
  743. avctx->has_b_frames);
  744. }
  745. } else {
  746. /*
  747. * An invalid frame has been consumed.
  748. */
  749. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
  750. "invalid PIB\n");
  751. avctx->has_b_frames--;
  752. copy_ret = RET_OK;
  753. }
  754. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  755. return copy_ret;
  756. } else if (ret == BC_STS_BUSY) {
  757. return RET_COPY_AGAIN;
  758. } else {
  759. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
  760. return RET_ERROR;
  761. }
  762. }
  763. static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
  764. {
  765. BC_STATUS ret;
  766. BC_DTS_STATUS decoder_status = { 0, };
  767. CopyRet rec_ret;
  768. CHDContext *priv = avctx->priv_data;
  769. HANDLE dev = priv->dev;
  770. uint8_t *in_data = avpkt->data;
  771. int len = avpkt->size;
  772. int free_data = 0;
  773. uint8_t pic_type = 0;
  774. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
  775. if (avpkt->size == 7 && !priv->bframe_bug) {
  776. /*
  777. * The use of a drop frame triggers the bug
  778. */
  779. av_log(avctx, AV_LOG_INFO,
  780. "CrystalHD: Enabling work-around for packed b-frame bug\n");
  781. priv->bframe_bug = 1;
  782. } else if (avpkt->size == 8 && priv->bframe_bug) {
  783. /*
  784. * Delay frames don't trigger the bug
  785. */
  786. av_log(avctx, AV_LOG_INFO,
  787. "CrystalHD: Disabling work-around for packed b-frame bug\n");
  788. priv->bframe_bug = 0;
  789. }
  790. if (len) {
  791. int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
  792. if (priv->parser) {
  793. int ret = 0;
  794. if (priv->bsfc) {
  795. ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL,
  796. &in_data, &len,
  797. avpkt->data, len, 0);
  798. }
  799. free_data = ret > 0;
  800. if (ret >= 0) {
  801. uint8_t *pout;
  802. int psize;
  803. int index;
  804. H264Context *h = priv->parser->priv_data;
  805. index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
  806. in_data, len, avctx->pkt->pts,
  807. avctx->pkt->dts, 0);
  808. if (index < 0) {
  809. av_log(avctx, AV_LOG_WARNING,
  810. "CrystalHD: Failed to parse h.264 packet to "
  811. "detect interlacing.\n");
  812. } else if (index != len) {
  813. av_log(avctx, AV_LOG_WARNING,
  814. "CrystalHD: Failed to parse h.264 packet "
  815. "completely. Interlaced frames may be "
  816. "incorrectly detected.\n");
  817. } else {
  818. av_log(avctx, AV_LOG_VERBOSE,
  819. "CrystalHD: parser picture type %d\n",
  820. h->s.picture_structure);
  821. pic_type = h->s.picture_structure;
  822. }
  823. } else {
  824. av_log(avctx, AV_LOG_WARNING,
  825. "CrystalHD: mp4toannexb filter failed to filter "
  826. "packet. Interlaced frames may be incorrectly "
  827. "detected.\n");
  828. }
  829. }
  830. if (len < tx_free - 1024) {
  831. /*
  832. * Despite being notionally opaque, either libcrystalhd or
  833. * the hardware itself will mangle pts values that are too
  834. * small or too large. The docs claim it should be in units
  835. * of 100ns. Given that we're nominally dealing with a black
  836. * box on both sides, any transform we do has no guarantee of
  837. * avoiding mangling so we need to build a mapping to values
  838. * we know will not be mangled.
  839. */
  840. uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type);
  841. if (!pts) {
  842. if (free_data) {
  843. av_freep(&in_data);
  844. }
  845. return AVERROR(ENOMEM);
  846. }
  847. av_log(priv->avctx, AV_LOG_VERBOSE,
  848. "input \"pts\": %"PRIu64"\n", pts);
  849. ret = DtsProcInput(dev, in_data, len, pts, 0);
  850. if (free_data) {
  851. av_freep(&in_data);
  852. }
  853. if (ret == BC_STS_BUSY) {
  854. av_log(avctx, AV_LOG_WARNING,
  855. "CrystalHD: ProcInput returned busy\n");
  856. usleep(BASE_WAIT);
  857. return AVERROR(EBUSY);
  858. } else if (ret != BC_STS_SUCCESS) {
  859. av_log(avctx, AV_LOG_ERROR,
  860. "CrystalHD: ProcInput failed: %u\n", ret);
  861. return -1;
  862. }
  863. avctx->has_b_frames++;
  864. } else {
  865. av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n");
  866. len = 0; // We didn't consume any bytes.
  867. }
  868. } else {
  869. av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
  870. }
  871. if (priv->skip_next_output) {
  872. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n");
  873. priv->skip_next_output = 0;
  874. avctx->has_b_frames--;
  875. return len;
  876. }
  877. ret = DtsGetDriverStatus(dev, &decoder_status);
  878. if (ret != BC_STS_SUCCESS) {
  879. av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
  880. return -1;
  881. }
  882. /*
  883. * No frames ready. Don't try to extract.
  884. *
  885. * Empirical testing shows that ReadyListCount can be a damn lie,
  886. * and ProcOut still fails when count > 0. The same testing showed
  887. * that two more iterations were needed before ProcOutput would
  888. * succeed.
  889. */
  890. if (priv->output_ready < 2) {
  891. if (decoder_status.ReadyListCount != 0)
  892. priv->output_ready++;
  893. usleep(BASE_WAIT);
  894. av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
  895. return len;
  896. } else if (decoder_status.ReadyListCount == 0) {
  897. /*
  898. * After the pipeline is established, if we encounter a lack of frames
  899. * that probably means we're not giving the hardware enough time to
  900. * decode them, so start increasing the wait time at the end of a
  901. * decode call.
  902. */
  903. usleep(BASE_WAIT);
  904. priv->decode_wait += WAIT_UNIT;
  905. av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
  906. return len;
  907. }
  908. do {
  909. rec_ret = receive_frame(avctx, data, got_frame);
  910. if (rec_ret == RET_OK && *got_frame == 0) {
  911. /*
  912. * This case is for when the encoded fields are stored
  913. * separately and we get a separate avpkt for each one. To keep
  914. * the pipeline stable, we should return nothing and wait for
  915. * the next time round to grab the second field.
  916. * H.264 PAFF is an example of this.
  917. */
  918. av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
  919. avctx->has_b_frames--;
  920. } else if (rec_ret == RET_COPY_NEXT_FIELD) {
  921. /*
  922. * This case is for when the encoded fields are stored in a
  923. * single avpkt but the hardware returns then separately. Unless
  924. * we grab the second field before returning, we'll slip another
  925. * frame in the pipeline and if that happens a lot, we're sunk.
  926. * So we have to get that second field now.
  927. * Interlaced mpeg2 and vc1 are examples of this.
  928. */
  929. av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
  930. while (1) {
  931. usleep(priv->decode_wait);
  932. ret = DtsGetDriverStatus(dev, &decoder_status);
  933. if (ret == BC_STS_SUCCESS &&
  934. decoder_status.ReadyListCount > 0) {
  935. rec_ret = receive_frame(avctx, data, got_frame);
  936. if ((rec_ret == RET_OK && *got_frame > 0) ||
  937. rec_ret == RET_ERROR)
  938. break;
  939. }
  940. }
  941. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
  942. } else if (rec_ret == RET_SKIP_NEXT_COPY) {
  943. /*
  944. * Two input packets got turned into a field pair. Gawd.
  945. */
  946. av_log(avctx, AV_LOG_VERBOSE,
  947. "Don't output on next decode call.\n");
  948. priv->skip_next_output = 1;
  949. }
  950. /*
  951. * If rec_ret == RET_COPY_AGAIN, that means that either we just handled
  952. * a FMT_CHANGE event and need to go around again for the actual frame,
  953. * we got a busy status and need to try again, or we're dealing with
  954. * packed b-frames, where the hardware strangely returns the packed
  955. * p-frame twice. We choose to keep the second copy as it carries the
  956. * valid pts.
  957. */
  958. } while (rec_ret == RET_COPY_AGAIN);
  959. usleep(priv->decode_wait);
  960. return len;
  961. }
  962. #if CONFIG_H264_CRYSTALHD_DECODER
  963. static AVClass h264_class = {
  964. "h264_crystalhd",
  965. av_default_item_name,
  966. options,
  967. LIBAVUTIL_VERSION_INT,
  968. };
  969. AVCodec ff_h264_crystalhd_decoder = {
  970. .name = "h264_crystalhd",
  971. .type = AVMEDIA_TYPE_VIDEO,
  972. .id = AV_CODEC_ID_H264,
  973. .priv_data_size = sizeof(CHDContext),
  974. .init = init,
  975. .close = uninit,
  976. .decode = decode,
  977. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  978. .flush = flush,
  979. .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
  980. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  981. .priv_class = &h264_class,
  982. };
  983. #endif
  984. #if CONFIG_MPEG2_CRYSTALHD_DECODER
  985. static AVClass mpeg2_class = {
  986. "mpeg2_crystalhd",
  987. av_default_item_name,
  988. options,
  989. LIBAVUTIL_VERSION_INT,
  990. };
  991. AVCodec ff_mpeg2_crystalhd_decoder = {
  992. .name = "mpeg2_crystalhd",
  993. .type = AVMEDIA_TYPE_VIDEO,
  994. .id = AV_CODEC_ID_MPEG2VIDEO,
  995. .priv_data_size = sizeof(CHDContext),
  996. .init = init,
  997. .close = uninit,
  998. .decode = decode,
  999. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1000. .flush = flush,
  1001. .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
  1002. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1003. .priv_class = &mpeg2_class,
  1004. };
  1005. #endif
  1006. #if CONFIG_MPEG4_CRYSTALHD_DECODER
  1007. static AVClass mpeg4_class = {
  1008. "mpeg4_crystalhd",
  1009. av_default_item_name,
  1010. options,
  1011. LIBAVUTIL_VERSION_INT,
  1012. };
  1013. AVCodec ff_mpeg4_crystalhd_decoder = {
  1014. .name = "mpeg4_crystalhd",
  1015. .type = AVMEDIA_TYPE_VIDEO,
  1016. .id = AV_CODEC_ID_MPEG4,
  1017. .priv_data_size = sizeof(CHDContext),
  1018. .init = init,
  1019. .close = uninit,
  1020. .decode = decode,
  1021. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1022. .flush = flush,
  1023. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
  1024. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1025. .priv_class = &mpeg4_class,
  1026. };
  1027. #endif
  1028. #if CONFIG_MSMPEG4_CRYSTALHD_DECODER
  1029. static AVClass msmpeg4_class = {
  1030. "msmpeg4_crystalhd",
  1031. av_default_item_name,
  1032. options,
  1033. LIBAVUTIL_VERSION_INT,
  1034. };
  1035. AVCodec ff_msmpeg4_crystalhd_decoder = {
  1036. .name = "msmpeg4_crystalhd",
  1037. .type = AVMEDIA_TYPE_VIDEO,
  1038. .id = AV_CODEC_ID_MSMPEG4V3,
  1039. .priv_data_size = sizeof(CHDContext),
  1040. .init = init,
  1041. .close = uninit,
  1042. .decode = decode,
  1043. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
  1044. .flush = flush,
  1045. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
  1046. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1047. .priv_class = &msmpeg4_class,
  1048. };
  1049. #endif
  1050. #if CONFIG_VC1_CRYSTALHD_DECODER
  1051. static AVClass vc1_class = {
  1052. "vc1_crystalhd",
  1053. av_default_item_name,
  1054. options,
  1055. LIBAVUTIL_VERSION_INT,
  1056. };
  1057. AVCodec ff_vc1_crystalhd_decoder = {
  1058. .name = "vc1_crystalhd",
  1059. .type = AVMEDIA_TYPE_VIDEO,
  1060. .id = AV_CODEC_ID_VC1,
  1061. .priv_data_size = sizeof(CHDContext),
  1062. .init = init,
  1063. .close = uninit,
  1064. .decode = decode,
  1065. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1066. .flush = flush,
  1067. .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
  1068. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1069. .priv_class = &vc1_class,
  1070. };
  1071. #endif
  1072. #if CONFIG_WMV3_CRYSTALHD_DECODER
  1073. static AVClass wmv3_class = {
  1074. "wmv3_crystalhd",
  1075. av_default_item_name,
  1076. options,
  1077. LIBAVUTIL_VERSION_INT,
  1078. };
  1079. AVCodec ff_wmv3_crystalhd_decoder = {
  1080. .name = "wmv3_crystalhd",
  1081. .type = AVMEDIA_TYPE_VIDEO,
  1082. .id = AV_CODEC_ID_WMV3,
  1083. .priv_data_size = sizeof(CHDContext),
  1084. .init = init,
  1085. .close = uninit,
  1086. .decode = decode,
  1087. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1088. .flush = flush,
  1089. .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
  1090. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1091. .priv_class = &wmv3_class,
  1092. };
  1093. #endif