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.

136 lines
3.0KB

  1. /*
  2. * Raw DV format
  3. * Copyright (c) 2002 Fabrice Bellard.
  4. *
  5. * This library 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 of the License, or (at your option) any later version.
  9. *
  10. * This library 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 this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. #define NTSC_FRAME_SIZE 120000
  21. #define PAL_FRAME_SIZE 144000
  22. typedef struct DVDemuxContext {
  23. int is_audio;
  24. } DVDemuxContext;
  25. /* raw input */
  26. static int dv_read_header(AVFormatContext *s,
  27. AVFormatParameters *ap)
  28. {
  29. AVStream *vst, *ast;
  30. vst = av_new_stream(s, 0);
  31. if (!vst)
  32. return AVERROR_NOMEM;
  33. vst->codec.codec_type = CODEC_TYPE_VIDEO;
  34. vst->codec.codec_id = CODEC_ID_DVVIDEO;
  35. #if 0
  36. ast = av_new_stream(s, 1);
  37. if (!ast)
  38. return AVERROR_NOMEM;
  39. ast->codec.codec_type = CODEC_TYPE_AUDIO;
  40. ast->codec.codec_id = CODEC_ID_DVAUDIO;
  41. #endif
  42. return 0;
  43. }
  44. /* XXX: build fake audio stream when DV audio decoder will be finished */
  45. int dv_read_packet(AVFormatContext *s,
  46. AVPacket *pkt)
  47. {
  48. int ret, size, dsf;
  49. uint8_t buf[4];
  50. ret = get_buffer(&s->pb, buf, 4);
  51. if (ret <= 0)
  52. return -EIO;
  53. dsf = buf[3] & 0x80;
  54. if (!dsf)
  55. size = NTSC_FRAME_SIZE;
  56. else
  57. size = PAL_FRAME_SIZE;
  58. if (av_new_packet(pkt, size) < 0)
  59. return -EIO;
  60. pkt->stream_index = 0;
  61. memcpy(pkt->data, buf, 4);
  62. ret = get_buffer(&s->pb, pkt->data + 4, size - 4);
  63. if (ret <= 0) {
  64. av_free_packet(pkt);
  65. return -EIO;
  66. }
  67. return ret;
  68. }
  69. int dv_read_close(AVFormatContext *s)
  70. {
  71. return 0;
  72. }
  73. AVInputFormat dv_iformat = {
  74. "dv",
  75. "DV video format",
  76. sizeof(DVDemuxContext),
  77. NULL,
  78. dv_read_header,
  79. dv_read_packet,
  80. dv_read_close,
  81. .extensions = "dv",
  82. };
  83. #if 0
  84. int dv_write_header(struct AVFormatContext *s)
  85. {
  86. return 0;
  87. }
  88. int dv_write_packet(struct AVFormatContext *s,
  89. int stream_index,
  90. unsigned char *buf, int size, int force_pts)
  91. {
  92. put_buffer(&s->pb, buf, size);
  93. put_flush_packet(&s->pb);
  94. return 0;
  95. }
  96. int dv_write_trailer(struct AVFormatContext *s)
  97. {
  98. return 0;
  99. }
  100. AVOutputFormat dv_oformat = {
  101. "dv",
  102. "DV video format",
  103. NULL,
  104. "dv",
  105. 0,
  106. CODEC_ID_DVVIDEO,
  107. CODEC_ID_DVAUDIO,
  108. dv_write_header,
  109. dv_write_packet,
  110. dv_write_trailer,
  111. };
  112. #endif
  113. int dv_init(void)
  114. {
  115. av_register_input_format(&dv_iformat);
  116. // av_register_output_format(&dv_oformat);
  117. return 0;
  118. }