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.

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