AVPlayer throwing : "Internal error: restarting too far ahead" - ios

I am observing KVO AVPlayerItemNewErrorLogEntryNotification of the AVPlayer and I find the following error:
errorStatusCode:-12645 errorDomain :CoreMediaErrorDomain
errorComment:Internal error: restarting too far ahead (-1.4084s)
I am unable to understand what the below line really means.
"Internal error: restarting too far ahead"
Can anyone help me to find the root cause of this issue.

If long .ts video file respons with: -12645.
There is no documentation for error status codes returned by MPMediaPlayer in MPMovieErrorLogEvent class.
But some of them are:
HTTP status - errorStatusCode - errorDomain - errorComment
400 -12666 CoreMediaErrorDomain unrecognized http response 400
401 -12937 CoreMediaErrorDomain Authentication Error
402 -12666 CoreMediaErrorDomain unrecognized http response 402
403 -12660 CoreMediaErrorDomain HTTP 403: Forbidden
404 -12938 CoreMediaErrorDomain HTTP 404: File not found
405 -12666 CoreMediaErrorDomain unrecognized http response 405
406 -12666 CoreMediaErrorDomain unrecognized http response 406
407 -12937 CoreMediaErrorDomain Authentication Error
409 -12666 CoreMediaErrorDomain unrecognized http response 409
...
415 -12666 CoreMediaErrorDomain unrecognized http response 415
500 -12666 CoreMediaErrorDomain unrecognized http response 500
501 -12666 CoreMediaErrorDomain unrecognized http response 501
502 -12666 CoreMediaErrorDomain unrecognized http response 502
503 -12661 CoreMediaErrorDomain HTTP 503: Unavailable
504 -12666 CoreMediaErrorDomain unrecognized http response 504
505 -12666 CoreMediaErrorDomain unrecognized http response 505
if long .ts video file respons -12645 CoreMediaErrorDomain No response for media file in 10 s
video .ts file bitrate differ from m3u8 declaration -12318 CoreMediaErrorDomain Segment exceeds specified bandwidth for variant
for live stream.playlist m3u8 did not change too long -12642 CoreMediaErrorDomain Playlist File unchanged for 2 consecutive reads
if wrong host ip -1004 kCFErrorDomainCFNetwork -
if wrong dns host name -1003 kCFErrorDomainCFNetwork -
if bad formatted URL -1000 kCFErrorDomainCFNetwork -
if invalid https/ssl request -1202 kCFErrorDomainCFNetwork -

According to an Apple employee this error message means that:
The player is complaining that it was trying to restart a live stream,
but only had 1.4 seconds of material available. How many segments are
in your live playlist? These days we recommend that you always have at
least six segments in the playlist. I believe the only effect is to
delay palyback until it has enough data.
Source: https://forums.developer.apple.com/thread/40791
The cause of the error most probably originates from the m3u8 itself.
When streaming a live program (e.g. any TV channel) there is a delay between the availability of event data and the encoder creating media segments (.ts) that are then appended to the playlist.
I could imagine that these types of errors are generated if the playerItem playhead's position is at the very edge of the buffer and new media segments are not made available fast enough on the server.
Should these errors be prevented or handled on the client's side:
Since these errors are reported as internal and AVPlayer apparently recovers from it, it is safe to assume that they are being handled internally. They could therefore be understood as simple error reporting and one could choose to ignore them.
If one wanted to prevent them, the only way to do this might be to manually set the live buffer's edge back in time a few seconds.

Related

AVPlayer won't play audio files from FFMPEG

Before requesting audio data AVPlayer requests byte range 0-1 from FFMPEG.
FFMPEG gives a 200 response, but AVPlayer requires a 206 response.
This results in the request failing and audio can't be played.
Expected behavior:
Play tracks when streaming through ffmpeg
Current behavior: When trying to stream with ffmpeg we get "Operation Stopped"
Sample FFMPEG command:
ffmpeg -i "/path/to/audio/track.mp3" -vn -strict -2 -acodec pcm_u8 -f wav -listen 1 -seekable 1 http://localhost:8090/restream.wav
Player Log:
Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x600003bcc4b0 {Error Domain=NSOSStatusErrorDomain Code=-12939 "(null)"}}
!av_interleaved_write_frame(): Broken pipe
!Connection to tcp://localhost:8090 failed: Connection refused
!Connection to tcp://localhost:8090 failed: Connection refused
!Connection to tcp://localhost:8090 failed: Connection refused
!Error writing trailer of http://localhost:8090/restream.wav: Broken pipe
This error is defined by Apple as:
+"The HTTP server sending the media resource is not configured as expected. This might mean that the server does not support byte range requests."
And summarised nicely in this StackOverflow post:
when AVPlayerItem receive a video URL , it do the following task:
Send a bytes request HTTP Request, and range = 0 -1
If the response code is 206 and return 1 bytes data, It do the 3th task, if not, AVErrorServerIncorrectlyConfigured error occurred.
continue send other HTTP Request, to download segment of All duration. and the response of VideoData code must be 206
In my situation , when send range[0-1] HTTP request, the server side give me a 200 OK response, So error occurred.
Network Log:
GET /file.wav HTTP/1.1
Host: localhost:1234
X-Playback-Session-Id: F72F1139-6F4C-4A22-B334-407672045A86
Range: bytes=0-1
Accept: */*
User-Agent: AppleCoreMedia/1.0.0.18C61 (iPhone; U; CPU OS 14_3 like Mac OS X; en_us)
Accept-Language: en-us
Accept-Encoding: identity
Connection: keep-alive
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Reproduce using this sample app:
This can also be reproduced using standard ffmpeg and adding URL to local or remote ffmpeg URL
Can we solve this by making changes to FFMPEG or AVPlayer?
I asked this question on the ffmpeg email list and it seems it's not possible:
If I understand your request correctly, you are not asking for a
change of a return type (you could probably do that yourself) but for
the implementation of byte range requests. I don't think this is
possible at all with FFmpeg.
Also it's not possible to get AVPlayer to ignore the byte range request:
it is an apple standard that media providers need to support http 1.1
with the range header (check out the iTunes store guidelines for
podcasts for example), so I wouldn't expect it anytime soon
SO Q'n: Is there a way to stop the avplayer sending a range http header field

Why I am getting different status code from ocelot?

I have a microservice project with ocelot API Gateway. In one service I have retuned 204(No Content) response. When I run that service directly then I am getting a proper response but when I run that service using ocelot then I am getting 500(Internal Server).
I have verified routing and it's fine because the same API return 200 or 201 then it called from ocelot successfully. But when 204 returns then it returns 500 but it should return 204.
I have checked logs it shows this information:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM4G9THO6LV0", Request id "0HM4G9THO6LV0:00000006": An unhandled exception was thrown by the application.
System.InvalidOperationException: Response Content-Length mismatch: too few bytes written (0 of 72).
Can anyone please help me?
Is there any configuration to handle the 204 status code in the ocelot API gateway?
I had the same problem. I checked my controllers and one of them return 204 with a response body. If you have the same issue you need to return 204 only.

The HTTP error code 502 returned frequently when calling Google EmbeddedAssistant API by Protocol Buffers over HTTP

I'm trying to call Google Assistant API using Protocol Buffers (protobuf) over HTTP. refer to:
https://googleapis.github.io/HowToRPC#grpc-fallback-experimental
My problem is that I frequently get HTTP error code 502 when sending request to the back-end service.
To test the problem, I wrote a python script to send (through HTTP POST) the pre-built protobuf binaries and check the response. The test results are:
32KB audio data (about 1 second length of audio), 20 times post, 0 times 502 error received / 32KB 20/0, failure rate: 0%
2*32KB, 20/0, failure rate: 0%
3*32KB, 20/3, failure rate: 15%
4*32KB, 20/10, failure rate: 50%
6*32KB, 20/19, failure rate: 95%
HTTP status code is 200 for successful requests, while 502 for failed cases.
where we can see, the larger audio length the greater failure rate.
The python code to post pre-built protobuf binaries is as below. while the content of file f1 is the just protobuf binaries.
def postData():
url = "https://embeddedassistant.googleapis.com/$rpc/google.assistant.embedded.v1alpha2.EmbeddedAssistant/Assist"
header = {"Content-type".encode('utf-8'): "application/x-protobuf".encode('utf-8'),"Accept".encode('utf-8'):"text/plain".encode('utf-8'), "Connection".encode('utf-8'):"keep-alive".encode('utf-8'), "Authorization".encode('utf-8'):repToken.encode('utf-8')}
with open(fl) as f:
r = requests.post(url, data=f, headers=header)
with open(fl + "_out", 'wb') as fd:
print(r.status_code)
fd.write(r.content)
f.close()
fd.close()
I also tried to post binary files which contain invalid protobuf, e.g a mp3 file,
and in this case, no matter the size of the file, the HTTP status code returned is always 400 with following message, which is just expected.
Invalid PROTO payload received. Invalid request data in stream body, unexpected message type: 7a
It seems the back-end service sets some kind of limitation for the latency of data transfer which makes it doesn’t work well with low bandwidth connections?

Frequent 504 Gateway Timeout errors in Microsoft Graph message api

I keep getting these for almost every request I make:
com.microsoft.graph.http.GraphFatalServiceException: Unexpected exception returned from the service.GET https://graph.microsoft.com/v1.0/users/me/messages?$filter=IsDraft+eq+false+and+ReceivedDateTime+ge+2017-09-06T12%3a02%3a26.608Z&$orderby=ReceivedDateTime+desc&$expand=SingleValueExtendedProperties(%24filter%3did+eq+%27String+0x7D%27)%2cattachments&$select=conversationId%2cchangeKey%2csentDateTime%2creceivedDateTime%2cisRead%2chasAttachments%2cinternetMessageHeaders%2csender%2cfrom%2ctoRecipients%2cccRecipients%2cbccRecipients%2csubject%2cinternetMessageId%2cbody%2cattachments&$top=100&$skip=6426
SdkVersion : graph-java-v0.2.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
client-request-id : 38246tl5hwutoukh6qb
504 : Gateway Timeout
Any chance on getting it resolved?

What's the right HTTP error code if parsing the request fails

If you create a web service which receives an processes some data like XML/JSON and the parsing of the data fails because it's incorrect, what do you do?
Send a HTTP 400 error code: After all it was the client who messed up the data (XML/JSON)
Send a HTTP 500 error code: It's the server who wasn't able to complete its task
If data in the request is malformed, then you'll want to return a 400 level error. Generally 500-level errors mean that something is wrong on the server that has nothing to do with the client or the client's request.
422 code.
422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server
understands the content type of the request entity (hence a
415(Unsupported Media Type) status code is inappropriate), and the
syntax of the request entity is correct (thus a 400 (Bad Request)
status code is inappropriate) but was unable to process the contained
instructions. For example, this error condition may occur if an XML
request body contains well-formed (i.e., syntactically correct), but
semantically erroneous, XML instructions
https://www.rfc-editor.org/rfc/rfc4918#section-11

Resources