PP_ERROR_BADRESOURCE when passing video stream from tabCapture to pp::MediaStreamVideoTrack::Configure

87 views
Skip to first unread message

cesar pachon

unread,
Apr 10, 2015, 6:18:45 PM4/10/15
to native-cli...@googlegroups.com
Hello,
I am passing the stream obtained in js with chrome.tabCapture api to my PNACL module, then I am trying to use it to configure a pp::MediaStreamVideoTrack to begin to access the video frames,
but most of the times I got a -5 error in the callback to pp::MediaStreamVideoTrack::Configure. Don't know how to deal with that error, because I am validating both in JS and in C++ that the stream and all other helper objects are valid..

this is part of my  code:

//---------- javascript -------------

var MediaStreamConstraint = {
        //audio: true,
        video: true,
        videoConstraints: {
            mandatory: {
                chromeMediaSource: 'tab',
                minWidth: 800,
                minHeight: 600,
                maxWidth: 800,
                maxHeight: 600
            }
        }
    };
    chrome.tabCapture.capture(MediaStreamConstraint, function(){
      console.log("background.js: Received local stream", stream);

  if( !stream.getVideoTracks().length){
    console.log("background.js: no stream available.");
    return;
  }
  var _track = stream.getVideoTracks()[0];
  console.log("background.js:gotStream: track: ", _track);

    console.log("background.js:gotStream:  sending stream to NACL");
    getModule().postMessage({command: 'init_stream', track: _track});

    stream.onended = function() { console.log("Ended"); };
});



//----------- c++ -----------------
/*
* this method is invoked as response to a javascript event, that passes a dictionary
*/
void MyEncoder::init(pp::VarDictionary &var_dictionary_message){

    pp::Var var_track = var_dictionary_message.Get("track");
    if (!var_track.is_resource()){
        log(" no var_track resource");
    return;
    }
   
    m_recording = false;
    m_frames_counter = 0;
    //m_capturing_single_frame = 0;
   
  log("MetacogEncoder::init: got the track!");
    pp::Resource resource_track = var_track.AsResource();
   
    video_track_ = pp::MediaStreamVideoTrack(resource_track);
   
    if(!video_track_ .IsMediaStreamVideoTrack(resource_track)){
       log( "validation of isMediaStreamVideoTrack failed :(");
    }
    ConfigureTrack(); 
  
}

//---------------
void MyEncoder::ConfigureTrack() {
    attrib_format_ = PP_VIDEOFRAME_FORMAT_BGRA;
    attrib_width_ = 1024;
    attrib_height_ = 768;

    const int32_t attrib_list[] = {
        PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT, attrib_format_,
        PP_MEDIASTREAMVIDEOTRACK_ATTRIB_WIDTH, attrib_width_,
        PP_MEDIASTREAMVIDEOTRACK_ATTRIB_HEIGHT, attrib_height_,
        PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE
    };
    log("MyEncoder::ConfigureTrack");

    video_track_.Configure(attrib_list, callback_factory_.NewCallback(
        &MyEncoder::OnConfigure));
};

//---------------------
void MyEncoder::OnConfigure(int32_t result) {
 
  if(result != PP_OK){
  log("MyEncoder::Configure failed, with async result=.", result); //this is a -5
  return;
  }
...
}

cesar pachon

unread,
Apr 13, 2015, 4:56:41 PM4/13/15
to native-cli...@googlegroups.com
btw,  video_track_.Configure is returning:

 PP_OK_COMPLETIONPENDING = -1,

as expected..

Bill Budge

unread,
Apr 14, 2015, 8:58:02 AM4/14/15
to native-cli...@googlegroups.com
Does it work if you use navigator.getUserMedia() instead of chrome.tabCapture?

cesar pachon

unread,
Apr 17, 2015, 9:30:28 AM4/17/15
to native-cli...@googlegroups.com
hello Bill thanks for the suggestion. I did hot had tested with navigator.getUserMedia because right now the behavior is the following: it always fails with error -5 the first time, then I close the popup, open a new tab and try again, and the second time it works as expected. I also noticed that the process from getting the stream in javascript and pass it to the native side takes more than 4 seconds, so I suspect that something needs a lot of time to get initialized properly.

I had not discovered any other explanation to the first failure scenario.
Reply all
Reply to author
Forward
0 new messages