static GF_Err VORB_GetCapabilities(GF_BaseDecoder *ifcg, GF_CodecCapability *capability) { VORBISCTX(); switch (capability->CapCode) { case GF_CODEC_RESILIENT: capability->cap.valueInt = 1; break; case GF_CODEC_OUTPUT_SIZE: capability->cap.valueInt = vorbis_info_blocksize(&ctx->vi, 1) * 2 * ctx->vi.channels; break; case GF_CODEC_SAMPLERATE: capability->cap.valueInt = ctx->vi.rate; break; case GF_CODEC_NB_CHAN: capability->cap.valueInt = ctx->vi.channels; break; case GF_CODEC_BITS_PER_SAMPLE: capability->cap.valueInt = 16; break; case GF_CODEC_BUFFER_MIN: capability->cap.valueInt = 4; break; case GF_CODEC_BUFFER_MAX: capability->cap.valueInt = ctx->vi.rate / 4 / vorbis_info_blocksize(&ctx->vi, 0); /*blocks are not of fixed size, so indicate a default CM size*/ //capability->cap.valueInt = 12 * vorbis_info_blocksize(&ctx->vi, 1) / vorbis_info_blocksize(&ctx->vi, 0); break; case GF_CODEC_CU_DURATION: /*this CANNOT work with vorbis, blocks are not of fixed size*/ capability->cap.valueInt = 0; break; case GF_CODEC_PADDING_BYTES: capability->cap.valueInt = 0; break; case GF_CODEC_CHANNEL_CONFIG: switch (ctx->vi.channels) { case 1: capability->cap.valueInt = GF_AUDIO_CH_FRONT_CENTER; break; case 2: capability->cap.valueInt = GF_AUDIO_CH_FRONT_LEFT | GF_AUDIO_CH_FRONT_RIGHT; break; case 3: capability->cap.valueInt = GF_AUDIO_CH_FRONT_LEFT | GF_AUDIO_CH_FRONT_RIGHT | GF_AUDIO_CH_FRONT_CENTER; break; case 4: capability->cap.valueInt = GF_AUDIO_CH_FRONT_LEFT | GF_AUDIO_CH_FRONT_RIGHT | GF_AUDIO_CH_BACK_LEFT | GF_AUDIO_CH_BACK_RIGHT; break; case 5: capability->cap.valueInt = GF_AUDIO_CH_FRONT_LEFT | GF_AUDIO_CH_FRONT_RIGHT | GF_AUDIO_CH_FRONT_CENTER | GF_AUDIO_CH_BACK_LEFT | GF_AUDIO_CH_BACK_RIGHT; break; case 6: capability->cap.valueInt = GF_AUDIO_CH_FRONT_LEFT | GF_AUDIO_CH_FRONT_RIGHT | GF_AUDIO_CH_FRONT_CENTER | GF_AUDIO_CH_BACK_LEFT | GF_AUDIO_CH_BACK_RIGHT | GF_AUDIO_CH_LFE; break; } break; default: capability->cap.valueInt = 0; break; } return GF_OK; }
static BseErrorType dh_vorbis_open (GslDataHandle *dhandle, GslDataHandleSetup *setup) { VorbisHandle *vhandle = (VorbisHandle*) dhandle; VFile *vfile; vorbis_info *vi; GslLong n, i; gint err; vfile = g_new0 (VFile, 1); vfile->rfile = gsl_rfile_open (vhandle->dhandle.name); if (!vfile->rfile) { g_free (vfile); return gsl_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED); } vfile->byte_length = gsl_rfile_length (vfile->rfile); if (vhandle->rfile_add_zoffset) { vfile->byte_offset = gsl_hfile_zoffset (vfile->rfile->hfile) + 1; vfile->byte_offset += vhandle->rfile_byte_offset; vfile->byte_offset = MIN (vfile->byte_offset, vfile->byte_length); vfile->byte_length -= vfile->byte_offset; } else { vfile->byte_offset = MIN (vhandle->rfile_byte_offset, vfile->byte_length); vfile->byte_length -= vfile->byte_offset; } if (vhandle->rfile_byte_length > 0) vfile->byte_length = MIN (vfile->byte_length, vhandle->rfile_byte_length); err = ov_open_callbacks (vfile, &vhandle->ofile, NULL, 0, vfile_ov_callbacks); if (err < 0) { if (0) g_printerr ("failed to open ogg at offset %d (real offset=%lld) (add-zoffset=%d): %s\n", vhandle->rfile_byte_offset, vfile->byte_offset, vhandle->rfile_add_zoffset, bse_error_blurb (ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED))); vfile_close (vfile); return ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED); } n = ov_streams (&vhandle->ofile); if (n > vhandle->bitstream) { vhandle->bitstream_serialno = ov_serialnumber (&vhandle->ofile, vhandle->bitstream); vhandle->n_bitstreams = n; if (0) g_printerr ("Ogg/Vorbis: opening ogg: bitstream=%d/%d serialno=%d\n", vhandle->bitstream, vhandle->n_bitstreams, vhandle->bitstream_serialno); } else { ov_clear (&vhandle->ofile); /* closes file */ return BSE_ERROR_NO_DATA; /* requested bitstream not available */ } vhandle->soffset = 0; for (i = 0; i < vhandle->bitstream; i++) vhandle->soffset += ov_pcm_total (&vhandle->ofile, i); n = ov_pcm_total (&vhandle->ofile, vhandle->bitstream); vi = ov_info (&vhandle->ofile, vhandle->bitstream); if (n > 0 && vi && vi->channels && ov_pcm_seek (&vhandle->ofile, vhandle->soffset) >= 0) { setup->n_channels = vi->channels; setup->n_values = n * setup->n_channels; } else { ov_clear (&vhandle->ofile); /* closes file */ return BSE_ERROR_NO_DATA; } vhandle->max_block_size = vorbis_info_blocksize (vi, 0); n = vorbis_info_blocksize (vi, 1); vhandle->max_block_size = MAX (vhandle->max_block_size, n); vhandle->pcm_pos = 0; vhandle->pcm_length = 0; setup->bit_depth = 24; setup->mix_freq = vi->rate; setup->needs_cache = TRUE; setup->xinfos = bse_xinfos_add_float (setup->xinfos, "osc-freq", vhandle->osc_freq); return BSE_ERROR_NONE; }
krad_vorbis_t *krad_vorbis_encoder_create (int channels, int sample_rate, float quality) { int ret; int pos; krad_vorbis_t *vorbis; ogg_packet header_main; ogg_packet header_comments; ogg_packet header_codebooks; vorbis = calloc (1, sizeof(krad_vorbis_t)); pos = 0; vorbis->error = 0; vorbis->state_str = ""; vorbis->channels = channels; vorbis->sample_rate = sample_rate; vorbis->quality = quality; vorbis_info_init (&vorbis->vinfo); printk ("KR Vorbis Encoder Version: %s", vorbis_version_string()); ret = vorbis_encode_init_vbr (&vorbis->vinfo, vorbis->channels, vorbis->sample_rate, vorbis->quality); if (ret < 0) { vorbis->error = ret; vorbis->state_str = "Krad Vorbis Encoder: vorbis_encode_init_vbr fail"; if (ret == OV_EIMPL) { vorbis->state_str = "Krad Vorbis Encoder: vorbis mode not supported"; } if (ret == OV_EINVAL) { vorbis->state_str = "Krad Vorbis Encoder: illegal vorbis mode"; } printke (vorbis->state_str); return vorbis; } vorbis->small_blocksz = vorbis_info_blocksize (&vorbis->vinfo, 0); vorbis->large_blocksz = vorbis_info_blocksize (&vorbis->vinfo, 1); printk ("KR Vorbis Encoder Setup: Channels %d Sample Rate: %d Quality: %f", vorbis->channels, vorbis->sample_rate, vorbis->quality); printk ("KR Vorbis Encoder Setup: Small Block Size: %u Large Block Size: %u", vorbis->small_blocksz, vorbis->large_blocksz); vorbis_analysis_init (&vorbis->vdsp, &vorbis->vinfo); vorbis_block_init (&vorbis->vdsp, &vorbis->vblock); vorbis_comment_init (&vorbis->vc); #ifdef KR_VERSION_STR_FULL vorbis_comment_add_tag (&vorbis->vc, "ENCODER", KR_VERSION_STR_FULL); #endif vorbis->header.codec = VORBIS; vorbis_analysis_headerout (&vorbis->vdsp, &vorbis->vc, &header_main, &header_comments, &header_codebooks); vorbis->hdrdata[0] = 0x02; vorbis->hdrdata[1] = (char)header_main.bytes; vorbis->hdrdata[2] = (char)header_comments.bytes; pos = 3; memcpy (vorbis->hdrdata + pos, header_main.packet, header_main.bytes); vorbis->header.data[0] = vorbis->hdrdata + pos; vorbis->header.sz[0] = header_main.bytes; pos += header_main.bytes; memcpy (vorbis->hdrdata + pos, header_comments.packet, header_comments.bytes); vorbis->header.data[1] = vorbis->hdrdata + pos; vorbis->header.sz[1] = header_comments.bytes; pos += header_comments.bytes; memcpy (vorbis->hdrdata + pos, header_codebooks.packet, header_codebooks.bytes); vorbis->header.data[2] = vorbis->hdrdata + pos; vorbis->header.sz[2] = header_codebooks.bytes; pos += header_codebooks.bytes; //vorbis->header.header_combined = vorbis->hdrdata; //vorbis->header.header_combined_size = pos; vorbis->header.count = 3; if (1) { printk ("KR Vorbis Encoder Setup: header test start"); krad_vorbis_test_headers (&vorbis->header); printk ("KR Vorbis Encoder Setup: header test end"); } vorbis->state_str = "Krad Vorbis Encoder: Init OK"; return vorbis; }