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.

138 lines
3.8KB

  1. /*
  2. * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avcodec.h"
  21. #include "libavutil/bswap.h"
  22. static av_cold int decode_init(AVCodecContext *avctx)
  23. {
  24. if(avctx->width & 1){
  25. av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
  26. return -1;
  27. }
  28. if(avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0)
  29. return -1;
  30. avctx->pix_fmt = PIX_FMT_YUV422P16;
  31. avctx->bits_per_raw_sample= 10;
  32. avctx->coded_frame= avcodec_alloc_frame();
  33. return 0;
  34. }
  35. static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
  36. {
  37. int y=0;
  38. int width= avctx->width;
  39. AVFrame *pic= avctx->coded_frame;
  40. const uint32_t *src= (const uint32_t *)avpkt->data;
  41. uint16_t *ydst, *udst, *vdst, *yend;
  42. if(pic->data[0])
  43. avctx->release_buffer(avctx, pic);
  44. if(avpkt->size < avctx->width * avctx->height * 8 / 3){
  45. av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
  46. return -1;
  47. }
  48. if(avpkt->size > avctx->width * avctx->height * 8 / 3){
  49. av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n");
  50. }
  51. pic->reference= 0;
  52. if(avctx->get_buffer(avctx, pic) < 0)
  53. return -1;
  54. ydst= (uint16_t *)pic->data[0];
  55. udst= (uint16_t *)pic->data[1];
  56. vdst= (uint16_t *)pic->data[2];
  57. yend= ydst + width;
  58. pic->pict_type= FF_I_TYPE;
  59. pic->key_frame= 1;
  60. for(;;){
  61. uint32_t v= be2me_32(*src++);
  62. *udst++= (v>>16) & 0xFFC0;
  63. *ydst++= (v>>6 ) & 0xFFC0;
  64. *vdst++= (v<<4 ) & 0xFFC0;
  65. v= be2me_32(*src++);
  66. *ydst++= (v>>16) & 0xFFC0;
  67. if(ydst >= yend){
  68. ydst+= pic->linesize[0]/2 - width;
  69. udst+= pic->linesize[1]/2 - width/2;
  70. vdst+= pic->linesize[2]/2 - width/2;
  71. yend= ydst + width;
  72. if(++y >= avctx->height)
  73. break;
  74. }
  75. *udst++= (v>>6 ) & 0xFFC0;
  76. *ydst++= (v<<4 ) & 0xFFC0;
  77. v= be2me_32(*src++);
  78. *vdst++= (v>>16) & 0xFFC0;
  79. *ydst++= (v>>6 ) & 0xFFC0;
  80. if(ydst >= yend){
  81. ydst+= pic->linesize[0]/2 - width;
  82. udst+= pic->linesize[1]/2 - width/2;
  83. vdst+= pic->linesize[2]/2 - width/2;
  84. yend= ydst + width;
  85. if(++y >= avctx->height)
  86. break;
  87. }
  88. *udst++= (v<<4 ) & 0xFFC0;
  89. v= be2me_32(*src++);
  90. *ydst++= (v>>16) & 0xFFC0;
  91. *vdst++= (v>>6 ) & 0xFFC0;
  92. *ydst++= (v<<4 ) & 0xFFC0;
  93. if(ydst >= yend){
  94. ydst+= pic->linesize[0]/2 - width;
  95. udst+= pic->linesize[1]/2 - width/2;
  96. vdst+= pic->linesize[2]/2 - width/2;
  97. yend= ydst + width;
  98. if(++y >= avctx->height)
  99. break;
  100. }
  101. }
  102. *data_size=sizeof(AVFrame);
  103. *(AVFrame*)data= *avctx->coded_frame;
  104. return avpkt->size;
  105. }
  106. AVCodec v210x_decoder = {
  107. "v210x",
  108. CODEC_TYPE_VIDEO,
  109. CODEC_ID_V210X,
  110. 0,
  111. decode_init,
  112. NULL,
  113. NULL,
  114. decode_frame,
  115. CODEC_CAP_DR1,
  116. };