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.

105 lines
3.0KB

  1. /*
  2. * Creative Voice File muxer.
  3. * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "voc.h"
  22. typedef struct voc_enc_context {
  23. int param_written;
  24. } voc_enc_context_t;
  25. static int voc_write_header(AVFormatContext *s)
  26. {
  27. ByteIOContext *pb = &s->pb;
  28. const int header_size = 26;
  29. const int version = 0x0114;
  30. if (s->nb_streams != 1
  31. || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO)
  32. return AVERROR_NOTSUPP;
  33. put_buffer(pb, voc_magic, sizeof(voc_magic) - 1);
  34. put_le16(pb, header_size);
  35. put_le16(pb, version);
  36. put_le16(pb, ~version + 0x1234);
  37. return 0;
  38. }
  39. static int voc_write_packet(AVFormatContext *s, AVPacket *pkt)
  40. {
  41. voc_enc_context_t *voc = s->priv_data;
  42. AVCodecContext *enc = s->streams[0]->codec;
  43. ByteIOContext *pb = &s->pb;
  44. if (!voc->param_written) {
  45. int format = codec_get_tag(voc_codec_tags, enc->codec_id);
  46. if (format > 0xFF) {
  47. put_byte(pb, VOC_TYPE_NEW_VOICE_DATA);
  48. put_le24(pb, pkt->size + 12);
  49. put_le32(pb, enc->sample_rate);
  50. put_byte(pb, enc->bits_per_sample);
  51. put_byte(pb, enc->channels);
  52. put_le16(pb, format);
  53. put_le32(pb, 0);
  54. } else {
  55. if (s->streams[0]->codec->channels > 1) {
  56. put_byte(pb, VOC_TYPE_EXTENDED);
  57. put_le24(pb, 4);
  58. put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels));
  59. put_byte(pb, format);
  60. put_byte(pb, enc->channels - 1);
  61. }
  62. put_byte(pb, VOC_TYPE_VOICE_DATA);
  63. put_le24(pb, pkt->size + 2);
  64. put_byte(pb, 256 - 1000000 / enc->sample_rate);
  65. put_byte(pb, format);
  66. }
  67. voc->param_written = 1;
  68. } else {
  69. put_byte(pb, VOC_TYPE_VOICE_DATA_CONT);
  70. put_le24(pb, pkt->size);
  71. }
  72. put_buffer(pb, pkt->data, pkt->size);
  73. return 0;
  74. }
  75. static int voc_write_trailer(AVFormatContext *s)
  76. {
  77. put_byte(&s->pb, 0);
  78. return 0;
  79. }
  80. AVOutputFormat voc_muxer = {
  81. "voc",
  82. "Creative Voice File format",
  83. "audio/x-voc",
  84. "voc",
  85. sizeof(voc_enc_context_t),
  86. CODEC_ID_PCM_U8,
  87. CODEC_ID_NONE,
  88. voc_write_header,
  89. voc_write_packet,
  90. voc_write_trailer,
  91. };