Search code examples
androidaudio-streamingrtspandroid-mediarecorderlibstreaming

E/MediaRecorder: start failed: -38


Here is my code. Basically I am trying to stream android screen to vlc media player using rtsp somehow I have managed to stream video perfectly but audio is not playing. I am using AMRNB encoding method to send stream on Local Socket. I can see that there is audio track by using log also it is being send but don't know why it is not getting played.

        mMediaRecorder.setAudioSource (mAudioSource);
        mMediaRecorder.setOutputFormat (mOutputFormat);
        mMediaRecorder.setAudioEncoder (mAudioEncoder);
        mMediaRecorder.setAudioChannels (1);
        mMediaRecorder.setAudioSamplingRate (mQuality.samplingRate);
        mMediaRecorder.setAudioEncodingBitRate (mQuality.bitRate);
        mMediaRecorder.setOutputFile (mSender.getFileDescriptor());
        mMediaRecorder.prepare();
        mMediaRecorder.start();
        Log.d(" audio ", mMediaRecorder.toString ());

        try {
            // mReceiver.getInputStream contains the data from the camera
            // the mPacketizer encapsulates this stream in an RTP stream and send it over the network
            mPacketizer.setDestination (mDestination, mRtpPort, mRtcpPort);
            mPacketizer.setInputStream (mReceiver.getInputStream ( ));
            mPacketizer.start ( );
            Log.d(" packetizer ", mPacketizer.toString ());
            mStreaming = true;
        } catch (IOException e) {
            stop ( );
            throw new IOException ("Something happened with the local sockets :/ Start failed !");
        }

Here is my Logcat

E/RtspServer: SETUP 192.168.1.86:25670/trackID=0
D/dest: 192.168.1.89
V/MediaStream: Requested audio with 32kbps at 8kHz
D/MediaRecorder: Constructor MediaRecorder
I/MediaRecorderJNI: setup
I/MediaRecorderJNI: setAudioSource(1)
I/MediaRecorderJNI: setAudioEncoder(2)
    setParameter()
I/MediaRecorderJNI: setParameter()
I/MediaRecorderJNI: setParameter()
I/MediaRecorderJNI: setOutputFile
    prepare
I/MediaRecorderJNI: start
E/MediaRecorder: start failed: -38
D/RtspServer: RTSP/1.0 200 OK
    Server: MajorKernelPanic RTSP Server
    Cseq: 4
    Content-Length: 0
    Transport: RTP/AVP/UDP;unicast;destination=192.168.1.89;client_port=5010-5011;server_port=33462-44704;ssrc=f6dc348c;mode=play
    Session: 1185d20035702ca
    Cache-Control: no-cache
E/RtspServer: SETUP 192.168.1.86:25670/trackID=1
D/dest: 192.168.1.89
D/H264Packetizer: H264 packetizer started !
    header is  0 0 0 1 33  ts = 76657985454000 nalu len = 24
D/RtspServer: RTSP/1.0 200 OK
    Server: MajorKernelPanic RTSP Server
    Cseq: 5
    Content-Length: 0
    Transport: RTP/AVP/UDP;unicast;destination=192.168.1.89;client_port=36882-36883;server_port=51731-41042;ssrc=e0e9342d;mode=play
    Session: 1185d20035702ca
    Cache-Control: no-cache
D/H264Packetizer: header is  -128 0 0 0 1  ts = 76658035880000 nalu len = 1333
D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10362; state: ENABLED

Solution

  • Updated

    While working on this, I found out that I was testing my project on android Lolipop and it is not possible to read and write directly on LocalSockets. You have to use ParcelFileDiscriptor to stream audio.