Пример #1
0
    AudioSystem::sample_t* JackAudioSystem::output_buffer(int index)
    {
	jack_nframes_t nframes = output_buffer_size(index);

	if(index == 0) {
	    assert(_port[0]);
	    return static_cast<float*>( jack_port_get_buffer(_port[0], nframes) );
	}else if(index == 1) {
	    assert(_port[1]);
	    return static_cast<float*>( jack_port_get_buffer(_port[1], nframes) );
	}
	return 0;
    }
	int VideoEncoderFfmpeg::Encode(int force_key_frame, int *is_key_frame)
	{
		if (bitrate() < 0)
			return 0;
		
		frag_writer()->Clear();
		frame_->pict_type = AV_PICTURE_TYPE_NONE != force_key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_NONE;
		int enc_size = avcodec_encode_video(context_,
			output_buffer(), output_buffer_size(), frame_);
		if (0 == enc_size)
			return 0;

		if (NULL != is_key_frame)
			*is_key_frame = frame_->key_frame;

		int size = 0;

		Fragmenter *fragmenter = GetFragmenter();
		if (fragsize() > 0 && NULL != fragmenter) {
#ifdef FRAG_FILE_DEBUG
			{
				static int frame_count_enc = 0;
				FILE *fd = NULL;
				char filename[50];
				sprintf_s(filename, "out_enc_%03d.dbg", frame_count_enc);
				_VERIFY(0 == fopen_s(&fd, filename, "wb"));
				fwrite(output_buffer(), enc_size, 1, fd);
				fclose(fd);
				++frame_count_enc;
			}
#endif
			size = fragmenter->Fragment(output_buffer(), enc_size);
		} else {
			size = enc_size;
			_VERIFY(frag_writer()->AppendItem(output_buffer(), enc_size));
		}
		*fragcount() = frag_writer()->frag_count();
		return size;
	}