📄 test.c
字号:
/***************************************************************************** * libreal - A library for writing and extracting data streams to and from * * RealMedia files. * * Copyright (C) 2001 Leo Howell * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) and later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA * * * * You can contact me by email, leo_howell@users.sourceforge.net * *****************************************************************************/#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include "libreal.h"int outfd;void my_read_data(int fd, unsigned long num_packets){ unsigned long i; RM_Media_Packet_Header packet; for (i = 0; i < num_packets; i++) { if (rm_read_media_packet_header(fd, &packet)) { puts("Error!"); exit(1); } printf("stream %2d: %3d bytes, timestamp %d\r", packet.stream_number, packet.length, packet.timestamp); rm_write_media_packet_header(outfd, &packet); free(packet.data); } printf("\nData packet read complete\n\n");}void my_read_indices(int fd, unsigned long num){ unsigned long i; RM_Index_Record rec; for (i=0; i<num; i++) { if (rm_read_index_record(fd, &rec)) { puts("Error"); exit(1); } printf("Read index #%d\r", i); rm_write_index_record(outfd, &rec); } printf("\nRead all indices\n\n");}int main(int argc, char **argv){ int fd; RM_Chunk chunk; char buf[4096]; puts("librm test"); fd = open("test.rm", O_RDONLY); outfd = open("test-out.rm", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); while (!rm_read_chunk(fd, &chunk)) { rm_write_chunk(outfd, &chunk); switch (chunk.header.object_id) { case FILE_HEADER_ID: printf("file version: %d\n" "num headers: %d\n\n", chunk.data.file_header.file_version, chunk.data.file_header.num_headers); break; case PROPERTIES_ID: printf("max bit rate\t%d\n" "avg bit rate\t%d\n" "max packet size\t%d\n" "avg packet size\t%d\n" "num packets\t%d\n" "duration\t%d\n" "preroll\t\t%d\n" "index offset\t%d\n" "data offset\t%d\n" "num streams\t%d\n" "flags\t\t%d\n\n", chunk.data.properties.max_bit_rate, chunk.data.properties.avg_bit_rate, chunk.data.properties.max_packet_size, chunk.data.properties.avg_packet_size, chunk.data.properties.num_packets, chunk.data.properties.duration, chunk.data.properties.preroll, chunk.data.properties.index_offset, chunk.data.properties.data_offset, chunk.data.properties.num_streams, chunk.data.properties.flags); break; case MEDIA_PROPERTIES_ID: strncpy(buf, chunk.data.media_properties.mime_type, chunk.data.media_properties.mime_type_size); buf[chunk.data.media_properties.mime_type_size] = '\0'; printf("stream number\t%d\n" "max bit rate\t%d\n" "avg bit rate\t%d\n" "max packet size\t%d\n" "avg packet size\t%d\n" "start time\t%d\n" "preroll\t\t%d\n" "duration\t%d\n" "stream name\t%s\n" "mime type\t%s\n\n", chunk.data.media_properties.stream_number, chunk.data.media_properties.max_bit_rate, chunk.data.media_properties.avg_bit_rate, chunk.data.media_properties.max_packet_size, chunk.data.media_properties.avg_packet_size, chunk.data.media_properties.start_time, chunk.data.media_properties.preroll, chunk.data.media_properties.duration, chunk.data.media_properties.stream_name, buf); free(chunk.data.media_properties.mime_type); break; case CONTENT_HEADER_ID: printf("title %s\n" "author %s\n" "copyright %s\n" "comment %s\n\n", chunk.data.content_description.title, chunk.data.content_description.author, chunk.data.content_description.copyright, chunk.data.content_description.comment); free(chunk.data.content_description.title); free(chunk.data.content_description.author); free(chunk.data.content_description.copyright); free(chunk.data.content_description.comment); break; case DATA_HEADER_ID: printf("num packets %d\n" "next header %d\n\n", chunk.data.data_chunk_header.num_packets, chunk.data.data_chunk_header.next_data_header); puts("BEGIN TO READ DATA"); my_read_data(fd, chunk.data.data_chunk_header.num_packets); break; case INDEX_HEADER_ID: printf("num indices %d\n" "stream number %d\n" "next index header %d\n\n", chunk.data.index_chunk_header.num_indices, chunk.data.index_chunk_header.stream_number, chunk.data.index_chunk_header.next_index_header); my_read_indices(fd, chunk.data.index_chunk_header.num_indices); break; } } close(outfd); close(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -