flvdec.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * FLV decoding.
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * FFmpeg is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with FFmpeg; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "mpegvideo.h"
  20. #include "h263.h"
  21. #include "flv.h"
  22. #include "libavcore/imgutils.h"
  23. void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){
  24. int is11 = get_bits1(gb);
  25. *last = get_bits1(gb);
  26. *run = get_bits(gb, 6);
  27. if(is11){
  28. *level = get_sbits(gb, 11);
  29. } else {
  30. *level = get_sbits(gb, 7);
  31. }
  32. }
  33. int ff_flv_decode_picture_header(MpegEncContext *s)
  34. {
  35. int format, width, height;
  36. /* picture header */
  37. if (get_bits_long(&s->gb, 17) != 1) {
  38. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  39. return -1;
  40. }
  41. format = get_bits(&s->gb, 5);
  42. if (format != 0 && format != 1) {
  43. av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
  44. return -1;
  45. }
  46. s->h263_flv = format+1;
  47. s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
  48. format = get_bits(&s->gb, 3);
  49. switch (format) {
  50. case 0:
  51. width = get_bits(&s->gb, 8);
  52. height = get_bits(&s->gb, 8);
  53. break;
  54. case 1:
  55. width = get_bits(&s->gb, 16);
  56. height = get_bits(&s->gb, 16);
  57. break;
  58. case 2:
  59. width = 352;
  60. height = 288;
  61. break;
  62. case 3:
  63. width = 176;
  64. height = 144;
  65. break;
  66. case 4:
  67. width = 128;
  68. height = 96;
  69. break;
  70. case 5:
  71. width = 320;
  72. height = 240;
  73. break;
  74. case 6:
  75. width = 160;
  76. height = 120;
  77. break;
  78. default:
  79. width = height = 0;
  80. break;
  81. }
  82. if(av_check_image_size(width, height, 0, s->avctx))
  83. return -1;
  84. s->width = width;
  85. s->height = height;
  86. s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2);
  87. s->dropable= s->pict_type > FF_P_TYPE;
  88. if (s->dropable)
  89. s->pict_type = FF_P_TYPE;
  90. skip_bits1(&s->gb); /* deblocking flag */
  91. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  92. s->h263_plus = 0;
  93. s->unrestricted_mv = 1;
  94. s->h263_long_vectors = 0;
  95. /* PEI */
  96. while (get_bits1(&s->gb) != 0) {
  97. skip_bits(&s->gb, 8);
  98. }
  99. s->f_code = 1;
  100. if(s->avctx->debug & FF_DEBUG_PICT_INFO){
  101. av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
  102. s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number);
  103. }
  104. s->y_dc_scale_table=
  105. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  106. return 0;
  107. }
  108. AVCodec flv_decoder = {
  109. "flv",
  110. AVMEDIA_TYPE_VIDEO,
  111. CODEC_ID_FLV1,
  112. sizeof(MpegEncContext),
  113. ff_h263_decode_init,
  114. NULL,
  115. ff_h263_decode_end,
  116. ff_h263_decode_frame,
  117. CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
  118. .max_lowres= 3,
  119. .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
  120. .pix_fmts= ff_pixfmt_list_420,
  121. };