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.

133 lines
3.5KB

  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. void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){
  23. int is11 = get_bits1(gb);
  24. *last = get_bits1(gb);
  25. *run = get_bits(gb, 6);
  26. if(is11){
  27. *level = get_sbits(gb, 11);
  28. } else {
  29. *level = get_sbits(gb, 7);
  30. }
  31. }
  32. int ff_flv_decode_picture_header(MpegEncContext *s)
  33. {
  34. int format, width, height;
  35. /* picture header */
  36. if (get_bits_long(&s->gb, 17) != 1) {
  37. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  38. return -1;
  39. }
  40. format = get_bits(&s->gb, 5);
  41. if (format != 0 && format != 1) {
  42. av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
  43. return -1;
  44. }
  45. s->h263_flv = format+1;
  46. s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
  47. format = get_bits(&s->gb, 3);
  48. switch (format) {
  49. case 0:
  50. width = get_bits(&s->gb, 8);
  51. height = get_bits(&s->gb, 8);
  52. break;
  53. case 1:
  54. width = get_bits(&s->gb, 16);
  55. height = get_bits(&s->gb, 16);
  56. break;
  57. case 2:
  58. width = 352;
  59. height = 288;
  60. break;
  61. case 3:
  62. width = 176;
  63. height = 144;
  64. break;
  65. case 4:
  66. width = 128;
  67. height = 96;
  68. break;
  69. case 5:
  70. width = 320;
  71. height = 240;
  72. break;
  73. case 6:
  74. width = 160;
  75. height = 120;
  76. break;
  77. default:
  78. width = height = 0;
  79. break;
  80. }
  81. if(avcodec_check_dimensions(s->avctx, width, height))
  82. return -1;
  83. s->width = width;
  84. s->height = height;
  85. s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2);
  86. s->dropable= s->pict_type > FF_P_TYPE;
  87. if (s->dropable)
  88. s->pict_type = FF_P_TYPE;
  89. skip_bits1(&s->gb); /* deblocking flag */
  90. s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
  91. s->h263_plus = 0;
  92. s->unrestricted_mv = 1;
  93. s->h263_long_vectors = 0;
  94. /* PEI */
  95. while (get_bits1(&s->gb) != 0) {
  96. skip_bits(&s->gb, 8);
  97. }
  98. s->f_code = 1;
  99. if(s->avctx->debug & FF_DEBUG_PICT_INFO){
  100. av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
  101. s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number);
  102. }
  103. s->y_dc_scale_table=
  104. s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
  105. return 0;
  106. }
  107. AVCodec flv_decoder = {
  108. "flv",
  109. AVMEDIA_TYPE_VIDEO,
  110. CODEC_ID_FLV1,
  111. sizeof(MpegEncContext),
  112. ff_h263_decode_init,
  113. NULL,
  114. ff_h263_decode_end,
  115. ff_h263_decode_frame,
  116. CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
  117. .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
  118. .pix_fmts= ff_pixfmt_list_420,
  119. };