コード例 #1
0
ファイル: soundstream.c プロジェクト: cran/R2SWF
void
writeSWFSoundWithSoundStreamToMethod(SWFSoundStream stream,
                            SWFByteOutputMethod method, void *data)
{
	int source = stream->streamSource;
	struct SWFSoundStreamBlock_s streamblock;

	/* need to get the sample count && and rewind */
	SWFSoundStream_getLength(stream, &streamblock);
	SWFSoundStream_rewind(stream);

	methodWriteUInt32(streamblock.numSamples, method, data);
	methodWriteUInt16(stream->initialDelay, method, data);
	if(source == STREAM_MP3)
		write_mp3(&streamblock, method, data);
	else if(source == STREAM_FLV)
		write_flv(&streamblock, method, data);
}
コード例 #2
0
ファイル: soundstream.c プロジェクト: cran/R2SWF
void
writeSWFSoundStreamToMethod(SWFBlock block,
                            SWFByteOutputMethod method, void *data)
{
	SWFSoundStreamBlock streamblock = (SWFSoundStreamBlock)block;
	int source = streamblock->stream->streamSource;
	
	if(source == STREAM_MP3)
	{
		methodWriteUInt16(streamblock->numSamples, method, data);
		methodWriteUInt16(streamblock->delay, method, data);
		write_mp3(streamblock, method, data);
	}
	else if(source == STREAM_FLV)
	{
		if(AUDIO_CODEC(streamblock->stream) == AUDIO_CODEC_MP3)
		{
			methodWriteUInt16(streamblock->numSamples, method, data);
			methodWriteUInt16(streamblock->delay, method, data);
		}
		write_flv(streamblock, method, data);
	}
}
コード例 #3
0
ファイル: update.c プロジェクト: GarfieldLinux/flvmeta
/* copy a FLV file while adding onMetaData and optionnally onLastSecond events */
int update_metadata(const flvmeta_opts * opts) {
    int res, in_place_update;
    flv_stream * flv_in;
    FILE * flv_out;
    flv_info info;
    flv_metadata meta;

    flv_in = flv_open(opts->input_file);
    if (flv_in == NULL) {
        return ERROR_OPEN_READ;
    }

    /*
        get all necessary information from the flv file
    */
    res = get_flv_info(flv_in, &info, opts);
    if (res != OK) {
        flv_close(flv_in);
        amf_data_free(info.keyframes);
        return res;
    }

    compute_metadata(&info, &meta, opts);

    /*
        open output file
    */
    /* detect whether we have to overwrite the input file */
    if (flvmeta_same_file(opts->input_file, opts->output_file)) {
        in_place_update = 1;
        flv_out = flvmeta_tmpfile();
    }
    else {
        in_place_update = 0;
        flv_out = fopen(opts->output_file, "wb");
    }

    if (flv_out == NULL) {
        flv_close(flv_in);
        amf_data_free(meta.on_last_second_name);
        amf_data_free(meta.on_last_second);
        amf_data_free(meta.on_metadata_name);
        amf_data_free(meta.on_metadata);
        amf_data_free(info.original_on_metadata);
        return ERROR_OPEN_WRITE;
    }

    /*
        write the output file
    */
    res = write_flv(flv_in, flv_out, &info, &meta, opts);

    flv_close(flv_in);
    amf_data_free(meta.on_last_second_name);
    amf_data_free(meta.on_last_second);
    amf_data_free(meta.on_metadata_name);
    amf_data_free(info.original_on_metadata);

    /* copy data into the original file if needed */
    if (in_place_update == 1) {
        FILE * flv_out_real;
        size_t bytes_read;
        byte copy_buffer[COPY_BUFFER_SIZE];

        flv_out_real = fopen(opts->output_file, "wb");
        if (flv_out_real == NULL) {
            amf_data_free(meta.on_metadata);
            return ERROR_OPEN_WRITE;
        }

        /* copy temporary file contents into the final file */
        lfs_fseek(flv_out, 0, SEEK_SET);
        while (!feof(flv_out)) {
            bytes_read = fread(copy_buffer, sizeof(byte), COPY_BUFFER_SIZE, flv_out);
            if (bytes_read > 0) {
                if (fwrite(copy_buffer, sizeof(byte), bytes_read, flv_out_real) < bytes_read) {
                    fclose(flv_out_real);
                    fclose(flv_out);
                    amf_data_free(meta.on_metadata);
                    return ERROR_WRITE;
                }
            }
            else {
                fclose(flv_out_real);
                fclose(flv_out);
                amf_data_free(meta.on_metadata);
                return ERROR_WRITE;
            }
        }
        
        fclose(flv_out_real);
    }
    fclose(flv_out);

    /* dump computed metadata if we have to */
    if (opts->dump_metadata == 1) {
        dump_amf_data(meta.on_metadata, opts);
    }
    
    amf_data_free(meta.on_metadata);
    return res;
}