Exemplo n.º 1
0
static
void trace_text(FILE *input, int output)
{
	struct ctf_stream_pos pos;
	ssize_t len;
	char *line = NULL, *nl;
	size_t linesize;
	int ret;

	memset(&pos, 0, sizeof(pos));
	ret = ctf_init_pos(&pos, NULL, output, O_RDWR);
	if (ret) {
		fprintf(stderr, "Error in ctf_init_pos\n");
		return;
	}
	write_packet_header(&pos, s_uuid);
	write_packet_context(&pos);
	for (;;) {
		len = getline(&line, &linesize, input);
		if (len < 0)
			break;
		nl = strrchr(line, '\n');
		if (nl) {
			*nl = '\0';
			trace_string(line, &pos, nl - line + 1);
		} else {
			trace_string(line, &pos, strlen(line) + 1);
		}
	}
	ret = ctf_fini_pos(&pos);
	if (ret) {
		fprintf(stderr, "Error in ctf_fini_pos\n");
	}
}
Exemplo n.º 2
0
Arquivo: rmenc.c Projeto: 1c0n/xbmc
static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
    uint8_t *buf1;
    RMMuxContext *rm = s->priv_data;
    AVIOContext *pb = s->pb;
    StreamInfo *stream = rm->audio_stream;
    int i;

    /* XXX: suppress this malloc */
    buf1 = av_malloc(size * sizeof(uint8_t));

    write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));

    if (stream->enc->codec_id == AV_CODEC_ID_AC3) {
        /* for AC-3, the words seem to be reversed */
        for(i=0;i<size;i+=2) {
            buf1[i] = buf[i+1];
            buf1[i+1] = buf[i];
        }
        avio_write(pb, buf1, size);
    } else {
        avio_write(pb, buf, size);
    }
    avio_flush(pb);
    stream->nb_frames++;
    av_free(buf1);
    return 0;
}
Exemplo n.º 3
0
static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
    RMMuxContext *rm = s->priv_data;
    AVIOContext *pb = s->pb;
    StreamInfo *stream = rm->video_stream;
    int key_frame = !!(flags & AV_PKT_FLAG_KEY);

    /* XXX: this is incorrect: should be a parameter */

    /* Well, I spent some time finding the meaning of these bits. I am
       not sure I understood everything, but it works !! */
#if 1
    if (size > MAX_PACKET_SIZE) {
        av_log(s, AV_LOG_ERROR, "Muxing packets larger than 64 kB (%d) is not supported\n", size);
        return AVERROR_PATCHWELCOME;
    }
    write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
    /* bit 7: '1' if final packet of a frame converted in several packets */
    avio_w8(pb, 0x81);
    /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
       frame starting from 1 */
    if (key_frame) {
        avio_w8(pb, 0x81);
    } else {
        avio_w8(pb, 0x01);
    }
    if(size >= 0x4000) {
        avio_wb32(pb, size); /* total frame size */
        avio_wb32(pb, size); /* offset from the start or the end */
    } else {
        avio_wb16(pb, 0x4000 | size); /* total frame size */
        avio_wb16(pb, 0x4000 | size); /* offset from the start or the end */
    }
#else
    /* full frame */
    write_packet_header(s, size + 6);
    avio_w8(pb, 0xc0);
    avio_wb16(pb, 0x4000 + size); /* total frame size */
    avio_wb16(pb, 0x4000 + packet_number * 126); /* position in stream */
#endif
    avio_w8(pb, stream->nb_frames & 0xff);

    avio_write(pb, buf, size);

    stream->nb_frames++;
    return 0;
}
Exemplo n.º 4
0
Arquivo: rmenc.c Projeto: AndyA/ffmbc
static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
    RMMuxContext *rm = s->priv_data;
    ByteIOContext *pb = s->pb;
    StreamInfo *stream = rm->video_stream;
    int key_frame = !!(flags & AV_PKT_FLAG_KEY);

    /* XXX: this is incorrect: should be a parameter */

    /* Well, I spent some time finding the meaning of these bits. I am
       not sure I understood everything, but it works !! */
#if 1
    write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
    /* bit 7: '1' if final packet of a frame converted in several packets */
    put_byte(pb, 0x81);
    /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
       frame starting from 1 */
    if (key_frame) {
        put_byte(pb, 0x81);
    } else {
        put_byte(pb, 0x01);
    }
    if(size >= 0x4000){
        put_be32(pb, size); /* total frame size */
        put_be32(pb, size); /* offset from the start or the end */
    }else{
        put_be16(pb, 0x4000 | size); /* total frame size */
        put_be16(pb, 0x4000 | size); /* offset from the start or the end */
    }
#else
    /* full frame */
    write_packet_header(s, size + 6);
    put_byte(pb, 0xc0);
    put_be16(pb, 0x4000 + size); /* total frame size */
    put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
#endif
    put_byte(pb, stream->nb_frames & 0xff);

    put_buffer(pb, buf, size);
    put_flush_packet(pb);

    stream->nb_frames++;
    return 0;
}
Exemplo n.º 5
0
int write_to_pcap(PacketFrame * frame)
{
    int res = 0;

    if(NULL == frame || NULL == frame->m_fp) return -1;

    if(0 == ftell(frame->m_fp)) {
        write_pcap_header(frame->m_fp);
    }

    res = write_packet_header(frame);
    res = write_packet_data(frame);

    return res;
}
Exemplo n.º 6
0
static
void trace_string(char *line, struct ctf_stream_pos *pos, size_t len)
{
	struct ctf_stream_pos dummy;
	int attempt = 0;
	char *tline = line;	/* tline is start of text, after timestamp */
	size_t tlen = len;
	uint64_t ts = 0;

	printf_debug("read: %s\n", line);

	for (;;) {
		int packet_filled = 0;

		ctf_dummy_pos(pos, &dummy);
		write_event_header(&dummy, line, &tline, len, &tlen, &ts);
		if (!ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT))
			packet_filled = 1;
		if (!ctf_move_pos(&dummy, tlen * CHAR_BIT))
			packet_filled = 1;
		if (packet_filled || ctf_pos_packet(&dummy)) {
			ctf_pos_pad_packet(pos);
			write_packet_header(pos, s_uuid);
			write_packet_context(pos);
			if (attempt++ == 1) {
				fprintf(stderr, "[Error] Line too large for packet size (%" PRIu64 "kB) (discarded)\n",
					pos->packet_size / CHAR_BIT / 1024);
				return;
			}
			continue;
		} else {
			break;
		}
	}

	write_event_header(pos, line, &tline, len, &tlen, &ts);
	if (!ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT))
		goto error;
	memcpy(ctf_get_pos_addr(pos), tline, tlen);
	if (!ctf_move_pos(pos, tlen * CHAR_BIT))
		goto error;
	return;

error:
	fprintf(stderr, "[error] Out of packet bounds when writing event payload\n");
	abort();
}
Exemplo n.º 7
0
static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
    RMMuxContext *rm = s->priv_data;
    AVIOContext *pb = s->pb;
    StreamInfo *stream = rm->audio_stream;
    int i;

    write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));

    if (stream->enc->codec_id == AV_CODEC_ID_AC3) {
        /* for AC-3, the words seem to be reversed */
        for (i = 0; i < size; i += 2) {
            avio_w8(pb, buf[i + 1]);
            avio_w8(pb, buf[i]);
        }
    } else {
        avio_write(pb, buf, size);
    }
    stream->nb_frames++;
    return 0;
}
Exemplo n.º 8
0
static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
{
    uint8_t *buf1;
    RMMuxContext *rm = s->priv_data;
    ByteIOContext *pb = s->pb;
    StreamInfo *stream = rm->audio_stream;
    int i;

    /* XXX: suppress this malloc */
    buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );

    write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));

    /* for AC-3, the words seem to be reversed */
    for(i=0; i<size; i+=2) {
        buf1[i] = buf[i+1];
        buf1[i+1] = buf[i];
    }
    put_buffer(pb, buf1, size);
    put_flush_packet(pb);
    stream->nb_frames++;
    av_free(buf1);
    return 0;
}