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.

148 lines
4.9KB

  1. /*
  2. * H.263i decoder
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "mpegutils.h"
  21. #include "mpegvideo.h"
  22. #include "h263.h"
  23. #include "mpegvideodata.h"
  24. /* don't understand why they choose a different header ! */
  25. int ff_intel_h263_decode_picture_header(MpegEncContext *s)
  26. {
  27. int format;
  28. if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
  29. return FRAME_SKIPPED;
  30. }
  31. /* picture header */
  32. if (get_bits_long(&s->gb, 22) != 0x20) {
  33. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  34. return -1;
  35. }
  36. s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
  37. if (get_bits1(&s->gb) != 1) {
  38. av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
  39. return -1; /* marker */
  40. }
  41. if (get_bits1(&s->gb) != 0) {
  42. av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
  43. return -1; /* H.263 id */
  44. }
  45. skip_bits1(&s->gb); /* split screen off */
  46. skip_bits1(&s->gb); /* camera off */
  47. skip_bits1(&s->gb); /* freeze picture release off */
  48. format = get_bits(&s->gb, 3);
  49. if (format == 0 || format == 6) {
  50. av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
  51. return -1;
  52. }
  53. s->h263_plus = 0;
  54. s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
  55. s->unrestricted_mv = get_bits1(&s->gb);
  56. s->h263_long_vectors = s->unrestricted_mv;
  57. if (get_bits1(&s->gb) != 0) {
  58. av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
  59. return -1; /* SAC: off */
  60. }
  61. s->obmc= get_bits1(&s->gb);
  62. s->pb_frame = get_bits1(&s->gb);
  63. if (format < 6) {
  64. s->width = ff_h263_format[format][0];
  65. s->height = ff_h263_format[format][1];
  66. s->avctx->sample_aspect_ratio.num = 12;
  67. s->avctx->sample_aspect_ratio.den = 11;
  68. } else {
  69. format = get_bits(&s->gb, 3);
  70. if(format == 0 || format == 7){
  71. av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
  72. return -1;
  73. }
  74. if(get_bits(&s->gb, 2))
  75. av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
  76. s->loop_filter = get_bits1(&s->gb);
  77. if(get_bits1(&s->gb))
  78. av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
  79. if(get_bits1(&s->gb))
  80. s->pb_frame = 2;
  81. if(get_bits(&s->gb, 5))
  82. av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
  83. if(get_bits(&s->gb, 5) != 1)
  84. av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
  85. }
  86. if(format == 6){
  87. int ar = get_bits(&s->gb, 4);
  88. skip_bits(&s->gb, 9); // display width
  89. skip_bits1(&s->gb);
  90. skip_bits(&s->gb, 9); // display height
  91. if(ar == 15){
  92. s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
  93. s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
  94. } else {
  95. s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
  96. }
  97. if (s->avctx->sample_aspect_ratio.num == 0)
  98. av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
  99. }
  100. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  101. skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
  102. if(s->pb_frame){
  103. skip_bits(&s->gb, 3); //temporal reference for B-frame
  104. skip_bits(&s->gb, 2); //dbquant
  105. }
  106. /* PEI */
  107. while (get_bits1(&s->gb) != 0) {
  108. skip_bits(&s->gb, 8);
  109. }
  110. s->f_code = 1;
  111. s->y_dc_scale_table=
  112. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  113. ff_h263_show_pict_info(s);
  114. return 0;
  115. }
  116. AVCodec ff_h263i_decoder = {
  117. .name = "h263i",
  118. .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
  119. .type = AVMEDIA_TYPE_VIDEO,
  120. .id = AV_CODEC_ID_H263I,
  121. .priv_data_size = sizeof(MpegEncContext),
  122. .init = ff_h263_decode_init,
  123. .close = ff_h263_decode_end,
  124. .decode = ff_h263_decode_frame,
  125. .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
  126. .pix_fmts = (const enum AVPixelFormat[]) {
  127. AV_PIX_FMT_YUV420P,
  128. AV_PIX_FMT_NONE
  129. },
  130. };