Results 1 to 10 of 10

Thread: Passing binary data from one module to another

  1. #1

    Default Passing binary data from one module to another

    I am trying to combine two module examples that I've seen on the forums. (If it makes a difference, these are all for live streaming)

    The first module is a module that has an SEI Listener. For my code, I get a subset of bytes from the H264SEIMessages and then I want to send them (via sendDirect? sendDirectAMF3?) so that the second module can detect them and convert them to ID3 tags.

    public class ModuleMediaStreamSEIListenerExample extends ModuleBase
    {
            public void onStreamCreate(IMediaStream stream)
    	{
    		// See linked thread; no changes from default adding of client listener
    	}
    
    	class SEIListener implements IMediaStreamH264SEINotify
    	{
    		public void onVideoH264Packet(IMediaStream arg0, AMFPacket arg1, H264SEIMessages arg2) {
                        byte[] theBytes = new byte[] { 0x46; 0x47}; // in reality, some processing to get some bytes;
    
                        NOT SURE WHAT GOES HERE.  I've tried the following:
                        AMFDataMixedArray data = new AMFDataMixedArray();
                        AMFDataByteArray da = AMFDataByteArray.wrap(theBytes);
                        data.put("someString", da);
    
                        // I've tried both of these; the reasons these don't work are described further down in the post
                        //stream.sendDirect("onCustomData", data);    
                        //stream.sendDirectAMF3("onCustomData", data);  
    		}
    	}
        ...
    }
    The second module is from the example to turn onText metadata into ID3 tags. In my case, however, I don't want text; I want binary.

    public class ModuleCupertinoLiveOnTextToID3 extends ModuleBase
    {
    	class LiveStreamPacketizerDataHandler implements IHTTPStreamerCupertinoLivePacketizerDataHandler
    	{
    		...
    		public void onFillChunkDataPacket(CupertinoPacketHolder holder, AMFPacket packet, ID3Frames id3Frames)
    		{			
    			while(true)
    			{
    				byte[] buffer = packet.getData();
    				if (buffer == null)
    					break;
    				
    				if (packet.getSize() <= 2)
    					break;
    				
    				int offset = 0;
    				if (buffer[0] == 0)
    					offset++;
    				
    				AMFDataList amfList = new AMFDataList(buffer, offset, buffer.length-offset);
    				
    				if (amfList.size() <= 1)
    					break;
    				
                                    // Note that I'm ignoring the type
                                    // if (amfList.get(0).getType() != AMFData.DATA_TYPE_STRING && amfList.get(1).getType() != AMFData.DATA_TYPE_OBJECT)
    				//	break;
    				
    				String metaDataStr = amfList.getString(0);
    				AMFDataObj dataObj = amfList.getObject(1);
    								
    				if (!metaDataStr.equalsIgnoreCase("onCustomData"))         // This is always false if I use sendDirectAMF3
    					break;
    				
    				AMFDataByteArray binaryData = (AMFDataByteArray) dataObj.get("someString");  // This is where the ClassCastException comes up if I use sendDirect
    
    				if (binaryData == null)
    					break;
    								
    				// Then put it in frames - outside the scope of this post
    			}
    		}
    	}
    If I use sendDirectAMF3 in the first example, then this fails:
    if (!metaDataStr.equalsIgnoreCase("onCustomData"))         // This is always false if I use sendDirectAMF3; otherwise, see where it fails below when I use sendDirect
        break;
    If I only use sendDirect, then it gets further, but I get a ClassCastException at:
    AMFDataByteArray binaryData = (AMFDataByteArray) dataObj.get("someString");

    Should I be using something other than AMFDataMixedArray and AMFDataByteArray to send the data? If so, then what is the corresponding means of receiving that data in the subsequent module? Is there something else I should be using besides sendDirect or sendDirectAMF3?

  2. #2
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Does your requirement involve caption data?

    Are you referring to this example?
    http://www.wowza.com/forums/content....point-MetaData

    Richard

  3. #3
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Sorry, I missed the title re binary data. I don't think sendDirect will do that, only text messages.

    You can use WMSProperties, put objects in the ApplicationInstance Properties container
    client.getAppInstance().getProperties().setProperty("var", "val");
    String var = client.getAppInstance().getProperties().getPropertyStr("var");
    // or in your case
    client.getAppInstance().getProperties().setProperty("obj", someAMFDataObj);
    AMFDataObj obj = (AMFDataObj)client.getAppInstance().getProperties().getProperty("obj");
    n

    Richard

  4. #4

    Default

    Inside of onFillChunkDataPacket, I don't have access to the client. That's a bit beside the point, as I could always access the applications properties to pass data around.

    I sort of want this data to be realtime and consistent across packets. Therefore, I would like to be able to inject that AMF-type data in one module and then when they appear in the other module, I would like to operate on them and inject ID3 frames, which would keep the timing of insertion to be relatively consistent.

    Any suggestions on how to use AMFDataByteArray?

  5. #5
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    What are you trying to do, at a higher level? What is the requirement? Captioning?

    You can combine these examples into one module.

    Richard

  6. #6

    Default

    There will be some binary userdata - not captions - embedded at an upstream encoder. Unfortunately, we weren't able to have them put in there exactly as we need them on the outbound side (of Wowza), so within Wowza we will need to grab that binary data and format it in a way that will be visible to iOS devices.

  7. #7

    Default

    Any suggestions on the binary data?

  8. #8
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    I asked around and got this suggestion: try using the com.wowza.util.Base64 api to transform the binary data to text.
    String base64DataStr = Base64.encodeBytes(byteArrayData, Base64.DONT_BREAK_LINES);
    Richard
    Last edited by rrlanham; 09-24-2012 at 09:32 AM.

  9. #9

    Default

    Just wanted to let thread viewers know that encoding to a string (and then decoding on the other side) is a satisfactory way to pass along the data. Of course, if you are hoping to use the binary data inside of an AMFDataMixedArray (on an Android client, for example), that won't work until the data is decoded.

  10. #10
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    Great. Thanks very much for the update

    Richard

Similar Threads

  1. Help passing data to Flash Player Please
    By drdialtone in forum Live Streaming and Encoder Discussion
    Replies: 3
    Last Post: 08-21-2012, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •