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.

144 lines
4.4KB

  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, opaque_length, 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. if (avctx->height == 486) {
  47. skip = 10;
  48. } else {
  49. skip = 16;
  50. }
  51. opaque_length = 2 * avctx->width * (avctx->height + skip) + 4 * interlaced;
  52. if (avpkt->size < opaque_length) {
  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 >= opaque_length * 2 + 4;
  58. srca = src + opaque_length + 5;
  59. pic->reference = 0;
  60. if (avctx->get_buffer(avctx, pic) < 0) {
  61. av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
  62. return AVERROR(ENOMEM);
  63. }
  64. pic->key_frame = 1;
  65. pic->pict_type = AV_PICTURE_TYPE_I;
  66. if (!interlaced) {
  67. src += avctx->width * skip;
  68. srca += avctx->width * skip;
  69. }
  70. for (i = 0; i < interlaced + 1; i++) {
  71. src += avctx->width * skip;
  72. srca += avctx->width * skip;
  73. if (interlaced && avctx->height == 486) {
  74. y = pic->data[0] + (1 - i) * pic->linesize[0];
  75. u = pic->data[1] + (1 - i) * pic->linesize[1];
  76. v = pic->data[2] + (1 - i) * pic->linesize[2];
  77. a = pic->data[3] + (1 - i) * pic->linesize[3];
  78. } else {
  79. y = pic->data[0] + i * pic->linesize[0];
  80. u = pic->data[1] + i * pic->linesize[1];
  81. v = pic->data[2] + i * pic->linesize[2];
  82. a = pic->data[3] + i * pic->linesize[3];
  83. }
  84. for (j = 0; j < avctx->height >> interlaced; j++) {
  85. for (k = 0; k < avctx->width >> 1; k++) {
  86. u[ k ] = *src++;
  87. y[2 * k ] = *src++;
  88. a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
  89. srca++;
  90. v[ k ] = *src++;
  91. y[2 * k + 1] = *src++;
  92. a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
  93. srca++;
  94. }
  95. y += (interlaced + 1) * pic->linesize[0];
  96. u += (interlaced + 1) * pic->linesize[1];
  97. v += (interlaced + 1) * pic->linesize[2];
  98. a += (interlaced + 1) * pic->linesize[3];
  99. }
  100. src += 4;
  101. srca += 4;
  102. }
  103. *data_size = sizeof(AVFrame);
  104. *(AVFrame *)data = *pic;
  105. return avpkt->size;
  106. }
  107. static av_cold int avui_decode_close(AVCodecContext *avctx)
  108. {
  109. if (avctx->coded_frame->data[0])
  110. avctx->release_buffer(avctx, avctx->coded_frame);
  111. av_freep(&avctx->coded_frame);
  112. return 0;
  113. }
  114. AVCodec ff_avui_decoder = {
  115. .name = "avui",
  116. .type = AVMEDIA_TYPE_VIDEO,
  117. .id = CODEC_ID_AVUI,
  118. .init = avui_decode_init,
  119. .decode = avui_decode_frame,
  120. .close = avui_decode_close,
  121. .capabilities = CODEC_CAP_DR1,
  122. .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),
  123. };