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.

146 lines
4.5KB

  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, 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. if (avpkt->size < 2 * avctx->width * (avctx->height + skip)
  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) *
  58. 2 * avctx->width + 4 + 8 * interlaced;
  59. srca = src + 2 * (avctx->height + skip) * 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;
  70. srca += avctx->width * skip;
  71. }
  72. for (i = 0; i < interlaced + 1; i++) {
  73. src += avctx->width * skip;
  74. srca += avctx->width * skip;
  75. if (interlaced && avctx->height == 486) {
  76. y = pic->data[0] + (1 - i) * pic->linesize[0];
  77. u = pic->data[1] + (1 - i) * pic->linesize[1];
  78. v = pic->data[2] + (1 - i) * pic->linesize[2];
  79. a = pic->data[3] + (1 - i) * pic->linesize[3];
  80. } else {
  81. y = pic->data[0] + i * pic->linesize[0];
  82. u = pic->data[1] + i * pic->linesize[1];
  83. v = pic->data[2] + i * pic->linesize[2];
  84. a = pic->data[3] + i * pic->linesize[3];
  85. }
  86. for (j = 0; j < avctx->height >> interlaced; j++) {
  87. for (k = 0; k < avctx->width >> 1; k++) {
  88. u[ k ] = *src++;
  89. y[2 * k ] = *src++;
  90. a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
  91. srca++;
  92. v[ k ] = *src++;
  93. y[2 * k + 1] = *src++;
  94. a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
  95. srca++;
  96. }
  97. y += (interlaced + 1) * pic->linesize[0];
  98. u += (interlaced + 1) * pic->linesize[1];
  99. v += (interlaced + 1) * pic->linesize[2];
  100. a += (interlaced + 1) * pic->linesize[3];
  101. }
  102. src += 4;
  103. srca += 4;
  104. }
  105. *data_size = sizeof(AVFrame);
  106. *(AVFrame *)data = *pic;
  107. return avpkt->size;
  108. }
  109. static av_cold int avui_decode_close(AVCodecContext *avctx)
  110. {
  111. if (avctx->coded_frame->data[0])
  112. avctx->release_buffer(avctx, avctx->coded_frame);
  113. av_freep(&avctx->coded_frame);
  114. return 0;
  115. }
  116. AVCodec ff_avui_decoder = {
  117. .name = "avui",
  118. .type = AVMEDIA_TYPE_VIDEO,
  119. .id = CODEC_ID_AVUI,
  120. .init = avui_decode_init,
  121. .decode = avui_decode_frame,
  122. .close = avui_decode_close,
  123. .capabilities = CODEC_CAP_DR1,
  124. .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),
  125. };