1

I want to make an application used to live in Android.I can capture video and audio data from camera and microphone,then send them to a PC-server in real-time by RTSP.

Then I find the spydroid and its libstreaming. And I make a example like its example1 used libstreaming.

But the result is that I can't find any video data send from android device to PC-server. Then I find there are something wrong in the VideoStream.java,the function named encodeWithMediaRecorder.(the device is in Android 4.44.)

mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setCamera(mCamera);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mMediaRecorder.setVideoEncoder(mVideoEncoder);
        mMediaRecorder.setPreviewDisplay(mSurfaceView.getHolder().getSurface());
        mMediaRecorder.setVideoSize(mRequestedQuality.resX,mRequestedQuality.resY);
        mMediaRecorder.setVideoFrameRate(mRequestedQuality.framerate);

        // The bandwidth actually consumed is often above what was requested 
        mMediaRecorder.setVideoEncodingBitRate((int)(mRequestedQuality.bitrate*0.8));

        // We write the output of the camera in a local socket instead of a file !          
        // This one little trick makes streaming feasible quiet simply: data from the camera
        // can then be manipulated at the other end of the socket
        FileDescriptor fd = null;
        if (sPipeApi == PIPE_API_PFD) {
            fd = mParcelWrite.getFileDescriptor();
        } else  {
            fd = mSender.getFileDescriptor();// actual execution
        }
        mMediaRecorder.setOutputFile(fd);

        mMediaRecorder.prepare();
        mMediaRecorder.start();

    } catch (Exception e) {
        throw new ConfNotSupportedException(e.getMessage());
    }

    InputStream is = null;

    if (sPipeApi == PIPE_API_PFD) {
        is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
    } else  {
        is = mReceiver.getInputStream();// actual execution
    }

    // This will skip the MPEG4 header if this step fails we can't stream anything :(
    try {
        byte buffer[] = new byte[4];
        // Skip all atoms preceding mdat atom
        while (!Thread.interrupted()) {
            while (is.read() != 'm');
            is.read(buffer,0,3);
            if (buffer[0] == 'd' && buffer[1] == 'a' && buffer[2] == 't') break;
        }
    } catch (IOException e) {
        Log.e(TAG,"Couldn't skip mp4 header :/");
        stop();
        throw e;
    }

It just get the video data from the camera,and output to a local socket .Then I get data after recoding in the stream "is".And I try to skip the mp4 head.

I get:

0 0 0 0
102 116 121 112       "ftyp"
51 103 112 52         "3qp$"
0 0 0 0
105 115 111 109       "isom"
51 103 112 52         "3qp$"
0 0 0 24
63 63 63 63           "????"
109 100 97 116        "mdat"

(Decimal) But after I read the 28 bytes,I try to read the byte No.29. may be is '?' I will have an io exception. "try again" Until about 2 minutes after the "mMediaRecorder.start()", I can read the "????","mdat",and so on....


It take me so much time ,may be there are some mistakes in the system version,may be there are some mistakes on the devices I used.But I can't find the true cause.So I'll thank you very much if you could give me some help T_T

Yieux
  • 41
  • 1
  • 2
  • 5

0 Answers0