ffm synchronization when using ffserver on revision 11463
Greetings, I have written an application that encodes synthesized video and provides it to ffserver in a similar manner to ffmpeg. However, I've noticed synchronization errors while reading ffm data. I've attached a patch to address these issues, and I'm looking for feedback. One issue occurs when reading the first header, when encountering a frame that does not include an offset in the initial packets. A frame header can not be found, and the ffm_read_data returns 0. However, the FFMContext pointers are not reset, so the ffm_read_data succeeds on a subsequent read, regardless of whether the header is next to be read. I've reset the FFMContext pointers upon this case, which appears to handle this case. The other issue is a loss of synchronization when ffserver is under load. Essentially, the size to be read does not align with the next header, as indicated between a mismatch of offset and size. I've spent days trying to understand why synchronization can be lost, so I'm hoping someone here will have some insight into the root cause. My patch only addresses the symptom, by trapping and recovering from the loss of synchronization. Thanks, Steve
This message is a resubmission, because I didn't submit correctly the first time. The patch is in-lined and an explanation follows afterwards. Thanks, Steve Index: libavformat/ffm.c =================================================================== --- libavformat/ffm.c (revision 11463) +++ libavformat/ffm.c (working copy) @@ -359,7 +359,8 @@ return -1; /* if first packet or resynchronization packet, we must handle it specifically */ - if (ffm->first_packet || (frame_offset & 0x8000)) { + if (ffm->first_packet || (frame_offset & 0x8000) + || (ffm->read_state == READ_HEADER && frame_offset && frame_offset - FFM_HEADER_SIZE != size)) { if (!frame_offset) { /* This packet has no frame headers in it */ if (url_ftell(pb) >= ffm->packet_size * 3) { @@ -367,6 +368,8 @@ goto retry_read; } /* This is bad, we cannot find a valid frame header */ + ffm->packet_end = ffm->packet; + ffm->packet_ptr = ffm->packet; return 0; } ffm->first_packet = 0; On Tue, 8 Jan 2008, Steve Webster wrote:
Greetings,
I have written an application that encodes synthesized video and provides it to ffserver in a similar manner to ffmpeg. However, I've noticed synchronization errors while reading ffm data. I've attached a patch to address these issues, and I'm looking for feedback.
One issue occurs when reading the first header, when encountering a frame that does not include an offset in the initial packets. A frame header can not be found, and the ffm_read_data returns 0. However, the FFMContext pointers are not reset, so the ffm_read_data succeeds on a subsequent read, regardless of whether the header is next to be read. I've reset the FFMContext pointers upon this case, which appears to handle this case.
The other issue is a loss of synchronization when ffserver is under load. Essentially, the size to be read does not align with the next header, as indicated between a mismatch of offset and size. I've spent days trying to understand why synchronization can be lost, so I'm hoping someone here will have some insight into the root cause. My patch only addresses the symptom, by trapping and recovering from the loss of synchronization.
Thanks, Steve
Steve Webster wrote:
This message is a resubmission, because I didn't submit correctly the first time. The patch is in-lined and an explanation follows afterwards.
I don't know what was supposed to have been incorrect about your previous submission, but inline (as opposed to attached) patches are considered undesirable, because they are subject to being mangled by mail clients. Patches should always be attached. In fact, I don't see anything wrong with your previous patch-submission post at all, except for having one line-break per paragraph instead of one line-break per ~80 characters. -- The Wanderer Warning: Simply because I argue an issue does not mean I agree with any side of it. Secrecy is the beginning of tyranny.
The Wanderer <inverseparadox at comcast.net> writes:
Steve Webster wrote:
This message is a resubmission, because I didn't submit correctly the first time. The patch is in-lined and an explanation follows afterwards.
I don't know what was supposed to have been incorrect about your previous submission, but inline (as opposed to attached) patches are considered undesirable, because they are subject to being mangled by mail clients. Patches should always be attached.
Attaching patches for inline display is fine, though. -- M?ns Rullg?rd mans at mansr.com
Hi Steve, Steve Webster wrote:
This message is a resubmission, because I didn't submit correctly the first time. The patch is in-lined and an explanation follows afterwards.
[...]
On Tue, 8 Jan 2008, Steve Webster wrote:
Greetings,
I have written an application that encodes synthesized video and provides it to ffserver in a similar manner to ffmpeg. However, I've noticed synchronization errors while reading ffm data. I've attached a patch to address these issues, and I'm looking for feedback.
Thanks for the contribution.
One issue occurs when reading the first header, when encountering a frame that does not include an offset in the initial packets. A frame header can not be found, and the ffm_read_data returns 0. However, the FFMContext pointers are not reset, so the ffm_read_data succeeds on a subsequent read, regardless of whether the header is next to be read. I've reset the FFMContext pointers upon this case, which appears to handle this case.
Yes, but like you say, this patch only address the symptom, I think this problem is fixed in latest svn, there was a problem with the seek function which didn't reset the read state after sucessful action. Any feedback is welcome.
The other issue is a loss of synchronization when ffserver is under load. Essentially, the size to be read does not align with the next header, as indicated between a mismatch of offset and size. I've spent days trying to understand why synchronization can be lost, so I'm hoping someone here will have some insight into the root cause. My patch only addresses the symptom, by trapping and recovering from the loss of synchronization.
Humm the load problem should be investigated further I think. Nonetheless, tests are needed with latest svn. Here it is pretty stable. Thanks. -- Baptiste COUDURIER GnuPG Key Id: 0x5C1ABAAA Smartjog USA Inc. http://www.smartjog.com Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
participants (4)
-
baptiste.coudurier@smartjog.com -
inverseparadox@comcast.net -
mans@mansr.com -
swebster@kinex.com