2

I am developing an app in which I am sending the video/audio encoded bytes from Server using MediaCodec to receiver via socket on same network.

At Receiver end, I am successfully fetching bytes. Now, I want to decode these bytes using MediaCodec and show them on SurfaceView or Some player.

Below is the code for receiving bytes:

  Thread serverThread = null;

  startServer();

 private void startServer() {

    this.serverThread = new Thread(new SocketThread());
    this.serverThread.start();
}

 private class SocketThread implements Runnable {
    @Override
    public void run() {

        Socket socket;
        try {
            serverSocket = new ServerSocket(SERVER_PORT);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (null != serverSocket) {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    socket = serverSocket.accept();
                    CommunicationThread commThread = new CommunicationThread(socket);
                    new Thread(commThread).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    class CommunicationThread implements Runnable {

        InputStream in;
        DataInputStream dis;

        public CommunicationThread(Socket clientSocket) {


            updateMessage("Server Started...");
        }

        public void run() {

            while (!Thread.currentThread().isInterrupted()) {

                try {

                    byte[] data = new byte[512];

                    fos.write(data);

                    // in.read(data, 0, data.length);


                } catch (Exception e) {                 

                    e.printStackTrace();

                    try {
                        fos.close();
                    } catch (Exception e1) {

                        e1.printStackTrace();
                    }
                }
            }
        }
    }
}

Bytes are successfully being received in byte[] data array.

Now, I want to decode these bytes using MediaCodec and play them on SurfaceView or player.

I followed following links for that but did not get proper understanding:

Mediacodec, decode byte packet from server and render it on surface

MediaCodec

I am stuck here at the end. Please provide some info so that I can proceed further.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ankit
  • 21
  • 3

0 Answers0