stream - Streaming engines best practice in C -
lang: c / env: linux
i developing streaming engine, able start, stop , pause stream, seeking operation that's giving me lot of headache, asked question here before , fixed issues inside code answers.
using lseek() function, passing open streaming file descriptor first argument, plus using udp transmitting, following code:
transport_fd = open(tsfile, o_rdonly); int offset = 1024; off_t offsetindicator; if ((offsetindicator=lseek(transport_fd, offset, seek_cur))<0) printf("error seeking\n");
whenever try seek while streaming, streaming stops , pictures hangs.
is there should pay attention to?, i.e: attempting sleep() or nanosleep() after seeking file in order changes take effect.
i couldn't find examples, papers or realted articles best practices in such engines.
edit:
after testing, seems file continued stream receiving devices on network didn't catch stream connection anymore, , calculating time took finish after subtract seeking time, stream seems finished normally.
code snippet:
while (!completed) { while (/* comparing conditions */ && !completed) { if (seeklck == 1) // seeklck semaphore test seek signal father process initiated 0 { int offset = 1024; off_t offsetindicator; if ((offsetindicator=lseek(transport_fd, offset, seek_cur))<0) printf("error seeking\n"); nanosleep(&nano_sleep_packet, 0); //try sleep see if still hanging, didn't work seeklck = 0; } len = read(transport_fd, send_buf, packet_size); if(len < 0) { fprintf(stderr, "file read error \n"); completed = 1; } else if (len == 0) { fprintf(stderr, "sent done\n"); completed = 1; } else { sent = sendto(sockfdstr, send_buf, len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); if(sent <= 0) { perror("send(): error "); completed = 1; } } } nanosleep(&nano_sleep_packet, 0); } close(transport_fd); close(sockfdstr); free(send_buf); printf("cleaning up\n"); return 0; }
the main question "why isn't file being streamed (played) when lseek() working fine?"...
actually nothing wrong server side, though, clients weren't able continue streaming after losing frame count (streaming ffmpeg frames, clients getting stream video scrambler).
what worked me in situation getting socket parameter , killing (in clean way) process needs seeked in while holding stream position, after start totally new stream seek position same socket parameter replaces old one.
i hope out there there's no documentation stuff.
Comments
Post a Comment