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.

1228 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);
  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. 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 (ff_get_buffer(avctx, priv->pic, AV_GET_BUFFER_FLAG_REF) < 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. *got_frame = 1;
  604. if ((ret = av_frame_ref(data, priv->pic)) < 0) {
  605. return ret;
  606. }
  607. }
  608. /*
  609. * Two types of PAFF content have been observed. One form causes the
  610. * hardware to return a field pair and the other individual fields,
  611. * even though the input is always individual fields. We must skip
  612. * copying on the next decode() call to maintain pipeline length in
  613. * the first case.
  614. */
  615. if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
  616. (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
  617. av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
  618. return RET_SKIP_NEXT_COPY;
  619. }
  620. /*
  621. * The logic here is purely based on empirical testing with samples.
  622. * If we need a second field, it could come from a second input packet,
  623. * or it could come from the same field-pair input packet at the current
  624. * field. In the first case, we should return and wait for the next time
  625. * round to get the second field, while in the second case, we should
  626. * ask the decoder for it immediately.
  627. *
  628. * Testing has shown that we are dealing with the fieldpair -> two fields
  629. * case if the VDEC_FLAG_UNKNOWN_SRC is not set or if the input picture
  630. * type was PICT_FRAME (in this second case, the flag might still be set)
  631. */
  632. return priv->need_second_field &&
  633. (!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ||
  634. pic_type == PICT_FRAME) ?
  635. RET_COPY_NEXT_FIELD : RET_OK;
  636. }
  637. static inline CopyRet receive_frame(AVCodecContext *avctx,
  638. void *data, int *got_frame)
  639. {
  640. BC_STATUS ret;
  641. BC_DTS_PROC_OUT output = {
  642. .PicInfo.width = avctx->width,
  643. .PicInfo.height = avctx->height,
  644. };
  645. CHDContext *priv = avctx->priv_data;
  646. HANDLE dev = priv->dev;
  647. *got_frame = 0;
  648. // Request decoded data from the driver
  649. ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output);
  650. if (ret == BC_STS_FMT_CHANGE) {
  651. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n");
  652. avctx->width = output.PicInfo.width;
  653. avctx->height = output.PicInfo.height;
  654. switch ( output.PicInfo.aspect_ratio ) {
  655. case vdecAspectRatioSquare:
  656. avctx->sample_aspect_ratio = (AVRational) { 1, 1};
  657. break;
  658. case vdecAspectRatio12_11:
  659. avctx->sample_aspect_ratio = (AVRational) { 12, 11};
  660. break;
  661. case vdecAspectRatio10_11:
  662. avctx->sample_aspect_ratio = (AVRational) { 10, 11};
  663. break;
  664. case vdecAspectRatio16_11:
  665. avctx->sample_aspect_ratio = (AVRational) { 16, 11};
  666. break;
  667. case vdecAspectRatio40_33:
  668. avctx->sample_aspect_ratio = (AVRational) { 40, 33};
  669. break;
  670. case vdecAspectRatio24_11:
  671. avctx->sample_aspect_ratio = (AVRational) { 24, 11};
  672. break;
  673. case vdecAspectRatio20_11:
  674. avctx->sample_aspect_ratio = (AVRational) { 20, 11};
  675. break;
  676. case vdecAspectRatio32_11:
  677. avctx->sample_aspect_ratio = (AVRational) { 32, 11};
  678. break;
  679. case vdecAspectRatio80_33:
  680. avctx->sample_aspect_ratio = (AVRational) { 80, 33};
  681. break;
  682. case vdecAspectRatio18_11:
  683. avctx->sample_aspect_ratio = (AVRational) { 18, 11};
  684. break;
  685. case vdecAspectRatio15_11:
  686. avctx->sample_aspect_ratio = (AVRational) { 15, 11};
  687. break;
  688. case vdecAspectRatio64_33:
  689. avctx->sample_aspect_ratio = (AVRational) { 64, 33};
  690. break;
  691. case vdecAspectRatio160_99:
  692. avctx->sample_aspect_ratio = (AVRational) {160, 99};
  693. break;
  694. case vdecAspectRatio4_3:
  695. avctx->sample_aspect_ratio = (AVRational) { 4, 3};
  696. break;
  697. case vdecAspectRatio16_9:
  698. avctx->sample_aspect_ratio = (AVRational) { 16, 9};
  699. break;
  700. case vdecAspectRatio221_1:
  701. avctx->sample_aspect_ratio = (AVRational) {221, 1};
  702. break;
  703. }
  704. return RET_COPY_AGAIN;
  705. } else if (ret == BC_STS_SUCCESS) {
  706. int copy_ret = -1;
  707. if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
  708. if (priv->last_picture == -1) {
  709. /*
  710. * Init to one less, so that the incrementing code doesn't
  711. * need to be special-cased.
  712. */
  713. priv->last_picture = output.PicInfo.picture_number - 1;
  714. }
  715. if (avctx->codec->id == AV_CODEC_ID_MPEG4 &&
  716. output.PicInfo.timeStamp == 0 && priv->bframe_bug) {
  717. av_log(avctx, AV_LOG_VERBOSE,
  718. "CrystalHD: Not returning packed frame twice.\n");
  719. priv->last_picture++;
  720. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  721. return RET_COPY_AGAIN;
  722. }
  723. print_frame_info(priv, &output);
  724. if (priv->last_picture + 1 < output.PicInfo.picture_number) {
  725. av_log(avctx, AV_LOG_WARNING,
  726. "CrystalHD: Picture Number discontinuity\n");
  727. /*
  728. * Have we lost frames? If so, we need to shrink the
  729. * pipeline length appropriately.
  730. *
  731. * XXX: I have no idea what the semantics of this situation
  732. * are so I don't even know if we've lost frames or which
  733. * ones.
  734. *
  735. * In any case, only warn the first time.
  736. */
  737. priv->last_picture = output.PicInfo.picture_number - 1;
  738. }
  739. copy_ret = copy_frame(avctx, &output, data, got_frame);
  740. if (*got_frame > 0) {
  741. avctx->has_b_frames--;
  742. priv->last_picture++;
  743. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n",
  744. avctx->has_b_frames);
  745. }
  746. } else {
  747. /*
  748. * An invalid frame has been consumed.
  749. */
  750. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with "
  751. "invalid PIB\n");
  752. avctx->has_b_frames--;
  753. copy_ret = RET_OK;
  754. }
  755. DtsReleaseOutputBuffs(dev, NULL, FALSE);
  756. return copy_ret;
  757. } else if (ret == BC_STS_BUSY) {
  758. return RET_COPY_AGAIN;
  759. } else {
  760. av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret);
  761. return RET_ERROR;
  762. }
  763. }
  764. static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
  765. {
  766. BC_STATUS ret;
  767. BC_DTS_STATUS decoder_status = { 0, };
  768. CopyRet rec_ret;
  769. CHDContext *priv = avctx->priv_data;
  770. HANDLE dev = priv->dev;
  771. uint8_t *in_data = avpkt->data;
  772. int len = avpkt->size;
  773. int free_data = 0;
  774. uint8_t pic_type = 0;
  775. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
  776. if (avpkt->size == 7 && !priv->bframe_bug) {
  777. /*
  778. * The use of a drop frame triggers the bug
  779. */
  780. av_log(avctx, AV_LOG_INFO,
  781. "CrystalHD: Enabling work-around for packed b-frame bug\n");
  782. priv->bframe_bug = 1;
  783. } else if (avpkt->size == 8 && priv->bframe_bug) {
  784. /*
  785. * Delay frames don't trigger the bug
  786. */
  787. av_log(avctx, AV_LOG_INFO,
  788. "CrystalHD: Disabling work-around for packed b-frame bug\n");
  789. priv->bframe_bug = 0;
  790. }
  791. if (len) {
  792. int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
  793. if (priv->parser) {
  794. int ret = 0;
  795. if (priv->bsfc) {
  796. ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL,
  797. &in_data, &len,
  798. avpkt->data, len, 0);
  799. }
  800. free_data = ret > 0;
  801. if (ret >= 0) {
  802. uint8_t *pout;
  803. int psize;
  804. int index;
  805. H264Context *h = priv->parser->priv_data;
  806. index = av_parser_parse2(priv->parser, avctx, &pout, &psize,
  807. in_data, len, avctx->pkt->pts,
  808. avctx->pkt->dts, 0);
  809. if (index < 0) {
  810. av_log(avctx, AV_LOG_WARNING,
  811. "CrystalHD: Failed to parse h.264 packet to "
  812. "detect interlacing.\n");
  813. } else if (index != len) {
  814. av_log(avctx, AV_LOG_WARNING,
  815. "CrystalHD: Failed to parse h.264 packet "
  816. "completely. Interlaced frames may be "
  817. "incorrectly detected.\n");
  818. } else {
  819. av_log(avctx, AV_LOG_VERBOSE,
  820. "CrystalHD: parser picture type %d\n",
  821. h->picture_structure);
  822. pic_type = h->picture_structure;
  823. }
  824. } else {
  825. av_log(avctx, AV_LOG_WARNING,
  826. "CrystalHD: mp4toannexb filter failed to filter "
  827. "packet. Interlaced frames may be incorrectly "
  828. "detected.\n");
  829. }
  830. }
  831. if (len < tx_free - 1024) {
  832. /*
  833. * Despite being notionally opaque, either libcrystalhd or
  834. * the hardware itself will mangle pts values that are too
  835. * small or too large. The docs claim it should be in units
  836. * of 100ns. Given that we're nominally dealing with a black
  837. * box on both sides, any transform we do has no guarantee of
  838. * avoiding mangling so we need to build a mapping to values
  839. * we know will not be mangled.
  840. */
  841. uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type);
  842. if (!pts) {
  843. if (free_data) {
  844. av_freep(&in_data);
  845. }
  846. return AVERROR(ENOMEM);
  847. }
  848. av_log(priv->avctx, AV_LOG_VERBOSE,
  849. "input \"pts\": %"PRIu64"\n", pts);
  850. ret = DtsProcInput(dev, in_data, len, pts, 0);
  851. if (free_data) {
  852. av_freep(&in_data);
  853. }
  854. if (ret == BC_STS_BUSY) {
  855. av_log(avctx, AV_LOG_WARNING,
  856. "CrystalHD: ProcInput returned busy\n");
  857. usleep(BASE_WAIT);
  858. return AVERROR(EBUSY);
  859. } else if (ret != BC_STS_SUCCESS) {
  860. av_log(avctx, AV_LOG_ERROR,
  861. "CrystalHD: ProcInput failed: %u\n", ret);
  862. return -1;
  863. }
  864. avctx->has_b_frames++;
  865. } else {
  866. av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n");
  867. len = 0; // We didn't consume any bytes.
  868. }
  869. } else {
  870. av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n");
  871. }
  872. if (priv->skip_next_output) {
  873. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n");
  874. priv->skip_next_output = 0;
  875. avctx->has_b_frames--;
  876. return len;
  877. }
  878. ret = DtsGetDriverStatus(dev, &decoder_status);
  879. if (ret != BC_STS_SUCCESS) {
  880. av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n");
  881. return -1;
  882. }
  883. /*
  884. * No frames ready. Don't try to extract.
  885. *
  886. * Empirical testing shows that ReadyListCount can be a damn lie,
  887. * and ProcOut still fails when count > 0. The same testing showed
  888. * that two more iterations were needed before ProcOutput would
  889. * succeed.
  890. */
  891. if (priv->output_ready < 2) {
  892. if (decoder_status.ReadyListCount != 0)
  893. priv->output_ready++;
  894. usleep(BASE_WAIT);
  895. av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n");
  896. return len;
  897. } else if (decoder_status.ReadyListCount == 0) {
  898. /*
  899. * After the pipeline is established, if we encounter a lack of frames
  900. * that probably means we're not giving the hardware enough time to
  901. * decode them, so start increasing the wait time at the end of a
  902. * decode call.
  903. */
  904. usleep(BASE_WAIT);
  905. priv->decode_wait += WAIT_UNIT;
  906. av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n");
  907. return len;
  908. }
  909. do {
  910. rec_ret = receive_frame(avctx, data, got_frame);
  911. if (rec_ret == RET_OK && *got_frame == 0) {
  912. /*
  913. * This case is for when the encoded fields are stored
  914. * separately and we get a separate avpkt for each one. To keep
  915. * the pipeline stable, we should return nothing and wait for
  916. * the next time round to grab the second field.
  917. * H.264 PAFF is an example of this.
  918. */
  919. av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n");
  920. avctx->has_b_frames--;
  921. } else if (rec_ret == RET_COPY_NEXT_FIELD) {
  922. /*
  923. * This case is for when the encoded fields are stored in a
  924. * single avpkt but the hardware returns then separately. Unless
  925. * we grab the second field before returning, we'll slip another
  926. * frame in the pipeline and if that happens a lot, we're sunk.
  927. * So we have to get that second field now.
  928. * Interlaced mpeg2 and vc1 are examples of this.
  929. */
  930. av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n");
  931. while (1) {
  932. usleep(priv->decode_wait);
  933. ret = DtsGetDriverStatus(dev, &decoder_status);
  934. if (ret == BC_STS_SUCCESS &&
  935. decoder_status.ReadyListCount > 0) {
  936. rec_ret = receive_frame(avctx, data, got_frame);
  937. if ((rec_ret == RET_OK && *got_frame > 0) ||
  938. rec_ret == RET_ERROR)
  939. break;
  940. }
  941. }
  942. av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n");
  943. } else if (rec_ret == RET_SKIP_NEXT_COPY) {
  944. /*
  945. * Two input packets got turned into a field pair. Gawd.
  946. */
  947. av_log(avctx, AV_LOG_VERBOSE,
  948. "Don't output on next decode call.\n");
  949. priv->skip_next_output = 1;
  950. }
  951. /*
  952. * If rec_ret == RET_COPY_AGAIN, that means that either we just handled
  953. * a FMT_CHANGE event and need to go around again for the actual frame,
  954. * we got a busy status and need to try again, or we're dealing with
  955. * packed b-frames, where the hardware strangely returns the packed
  956. * p-frame twice. We choose to keep the second copy as it carries the
  957. * valid pts.
  958. */
  959. } while (rec_ret == RET_COPY_AGAIN);
  960. usleep(priv->decode_wait);
  961. return len;
  962. }
  963. #if CONFIG_H264_CRYSTALHD_DECODER
  964. static AVClass h264_class = {
  965. "h264_crystalhd",
  966. av_default_item_name,
  967. options,
  968. LIBAVUTIL_VERSION_INT,
  969. };
  970. AVCodec ff_h264_crystalhd_decoder = {
  971. .name = "h264_crystalhd",
  972. .type = AVMEDIA_TYPE_VIDEO,
  973. .id = AV_CODEC_ID_H264,
  974. .priv_data_size = sizeof(CHDContext),
  975. .init = init,
  976. .close = uninit,
  977. .decode = decode,
  978. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  979. .flush = flush,
  980. .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"),
  981. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  982. .priv_class = &h264_class,
  983. };
  984. #endif
  985. #if CONFIG_MPEG2_CRYSTALHD_DECODER
  986. static AVClass mpeg2_class = {
  987. "mpeg2_crystalhd",
  988. av_default_item_name,
  989. options,
  990. LIBAVUTIL_VERSION_INT,
  991. };
  992. AVCodec ff_mpeg2_crystalhd_decoder = {
  993. .name = "mpeg2_crystalhd",
  994. .type = AVMEDIA_TYPE_VIDEO,
  995. .id = AV_CODEC_ID_MPEG2VIDEO,
  996. .priv_data_size = sizeof(CHDContext),
  997. .init = init,
  998. .close = uninit,
  999. .decode = decode,
  1000. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1001. .flush = flush,
  1002. .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"),
  1003. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1004. .priv_class = &mpeg2_class,
  1005. };
  1006. #endif
  1007. #if CONFIG_MPEG4_CRYSTALHD_DECODER
  1008. static AVClass mpeg4_class = {
  1009. "mpeg4_crystalhd",
  1010. av_default_item_name,
  1011. options,
  1012. LIBAVUTIL_VERSION_INT,
  1013. };
  1014. AVCodec ff_mpeg4_crystalhd_decoder = {
  1015. .name = "mpeg4_crystalhd",
  1016. .type = AVMEDIA_TYPE_VIDEO,
  1017. .id = AV_CODEC_ID_MPEG4,
  1018. .priv_data_size = sizeof(CHDContext),
  1019. .init = init,
  1020. .close = uninit,
  1021. .decode = decode,
  1022. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1023. .flush = flush,
  1024. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"),
  1025. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1026. .priv_class = &mpeg4_class,
  1027. };
  1028. #endif
  1029. #if CONFIG_MSMPEG4_CRYSTALHD_DECODER
  1030. static AVClass msmpeg4_class = {
  1031. "msmpeg4_crystalhd",
  1032. av_default_item_name,
  1033. options,
  1034. LIBAVUTIL_VERSION_INT,
  1035. };
  1036. AVCodec ff_msmpeg4_crystalhd_decoder = {
  1037. .name = "msmpeg4_crystalhd",
  1038. .type = AVMEDIA_TYPE_VIDEO,
  1039. .id = AV_CODEC_ID_MSMPEG4V3,
  1040. .priv_data_size = sizeof(CHDContext),
  1041. .init = init,
  1042. .close = uninit,
  1043. .decode = decode,
  1044. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
  1045. .flush = flush,
  1046. .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"),
  1047. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1048. .priv_class = &msmpeg4_class,
  1049. };
  1050. #endif
  1051. #if CONFIG_VC1_CRYSTALHD_DECODER
  1052. static AVClass vc1_class = {
  1053. "vc1_crystalhd",
  1054. av_default_item_name,
  1055. options,
  1056. LIBAVUTIL_VERSION_INT,
  1057. };
  1058. AVCodec ff_vc1_crystalhd_decoder = {
  1059. .name = "vc1_crystalhd",
  1060. .type = AVMEDIA_TYPE_VIDEO,
  1061. .id = AV_CODEC_ID_VC1,
  1062. .priv_data_size = sizeof(CHDContext),
  1063. .init = init,
  1064. .close = uninit,
  1065. .decode = decode,
  1066. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1067. .flush = flush,
  1068. .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"),
  1069. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1070. .priv_class = &vc1_class,
  1071. };
  1072. #endif
  1073. #if CONFIG_WMV3_CRYSTALHD_DECODER
  1074. static AVClass wmv3_class = {
  1075. "wmv3_crystalhd",
  1076. av_default_item_name,
  1077. options,
  1078. LIBAVUTIL_VERSION_INT,
  1079. };
  1080. AVCodec ff_wmv3_crystalhd_decoder = {
  1081. .name = "wmv3_crystalhd",
  1082. .type = AVMEDIA_TYPE_VIDEO,
  1083. .id = AV_CODEC_ID_WMV3,
  1084. .priv_data_size = sizeof(CHDContext),
  1085. .init = init,
  1086. .close = uninit,
  1087. .decode = decode,
  1088. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
  1089. .flush = flush,
  1090. .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"),
  1091. .pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUYV422, AV_PIX_FMT_NONE},
  1092. .priv_class = &wmv3_class,
  1093. };
  1094. #endif