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.

139 lines
4.3KB

  1. /*
  2. * AVID Meridien decoder
  3. *
  4. * Copyright (c) 2012 Carl Eugen Hoyos
  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. #include "avcodec.h"
  23. static av_cold int avui_decode_init(AVCodecContext *avctx)
  24. {
  25. avctx->pix_fmt = PIX_FMT_YUVA422P;
  26. avctx->coded_frame = avcodec_alloc_frame();
  27. if (!avctx->coded_frame) {
  28. av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
  29. return AVERROR(ENOMEM);
  30. }
  31. return 0;
  32. }
  33. static int avui_decode_frame(AVCodecContext *avctx, void *data,
  34. int *data_size, AVPacket *avpkt)
  35. {
  36. AVFrame *pic = avctx->coded_frame;
  37. const uint8_t *src = avpkt->data;
  38. const uint8_t *srca;
  39. uint8_t *y, *u, *v, *a;
  40. int transparent, interlaced = 1, skip[2], i, j, k;
  41. if (pic->data[0])
  42. avctx->release_buffer(avctx, pic);
  43. if (!memcmp(&avctx->extradata[4], "APRGAPRG0001", 12) &&
  44. avctx->extradata_size >= 24)
  45. interlaced = avctx->extradata[19] != 1;
  46. skip[0] = skip[1] = 16;
  47. if (avctx->height == 486) {
  48. skip[0] = 8;
  49. skip[1] = 12;
  50. }
  51. if (avpkt->size < avctx->width * (2 * avctx->height + skip[0] + skip[1])
  52. + 4 * interlaced) {
  53. av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
  54. return AVERROR(EINVAL);
  55. }
  56. transparent = avctx->bits_per_coded_sample == 32 &&
  57. avpkt->size >= (2 * avctx->height + skip[0] + skip[1]) *
  58. 2 * avctx->width + 4 + 8 * interlaced;
  59. srca = src + (2 * avctx->height + skip[0] + skip[1]) * avctx->width
  60. + 5 + interlaced * 4;
  61. pic->reference = 0;
  62. if (avctx->get_buffer(avctx, pic) < 0) {
  63. av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
  64. return AVERROR(ENOMEM);
  65. }
  66. pic->key_frame = 1;
  67. pic->pict_type = AV_PICTURE_TYPE_I;
  68. if (!interlaced) {
  69. src += avctx->width * skip[1];
  70. srca += avctx->width * skip[1];
  71. }
  72. for (i = 0; i < interlaced + 1; i++) {
  73. src += avctx->width * skip[i];
  74. srca += avctx->width * skip[i];
  75. y = pic->data[0] + i * pic->linesize[0];
  76. u = pic->data[1] + i * pic->linesize[1];
  77. v = pic->data[2] + i * pic->linesize[2];
  78. a = pic->data[3] + i * pic->linesize[3];
  79. for (j = 0; j < avctx->height >> interlaced; j++) {
  80. for (k = 0; k < avctx->width >> 1; k++) {
  81. u[ k ] = *src++;
  82. y[2 * k ] = *src++;
  83. a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
  84. srca++;
  85. v[ k ] = *src++;
  86. y[2 * k + 1] = *src++;
  87. a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
  88. srca++;
  89. }
  90. y += (interlaced + 1) * pic->linesize[0];
  91. u += (interlaced + 1) * pic->linesize[1];
  92. v += (interlaced + 1) * pic->linesize[2];
  93. a += (interlaced + 1) * pic->linesize[3];
  94. }
  95. src += 4;
  96. srca += 4;
  97. }
  98. *data_size = sizeof(AVFrame);
  99. *(AVFrame *)data = *pic;
  100. return avpkt->size;
  101. }
  102. static av_cold int avui_decode_close(AVCodecContext *avctx)
  103. {
  104. if (avctx->coded_frame->data[0])
  105. avctx->release_buffer(avctx, avctx->coded_frame);
  106. av_freep(&avctx->coded_frame);
  107. return 0;
  108. }
  109. AVCodec ff_avui_decoder = {
  110. .name = "avui",
  111. .type = AVMEDIA_TYPE_VIDEO,
  112. .id = CODEC_ID_AVUI,
  113. .init = avui_decode_init,
  114. .decode = avui_decode_frame,
  115. .close = avui_decode_close,
  116. .capabilities = CODEC_CAP_DR1,
  117. .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),
  118. };