comparison stream/tvi_dshow.c @ 25084:f72ebba1e6d1

pass chain structure instead of several variables to build_sub_graph
author voroshil
date Mon, 19 Nov 2007 19:33:53 +0000
parents b0f91db30cb2
children da7c8d1b7a36
comparison
equal deleted inserted replaced
25083:b0f91db30cb2 25084:f72ebba1e6d1
1300 * \param pbuf ringbuffer data structure 1300 * \param pbuf ringbuffer data structure
1301 * \param pmt media type for chain (AM_MEDIA_TYPE) 1301 * \param pmt media type for chain (AM_MEDIA_TYPE)
1302 * 1302 *
1303 * \note routine does not frees memory, allocated for grabber_rinbuffer_s structure 1303 * \note routine does not frees memory, allocated for grabber_rinbuffer_s structure
1304 */ 1304 */
1305 static HRESULT build_sub_graph(priv_t * priv, IBaseFilter * pCaptureFilter, 1305 static HRESULT build_sub_graph(priv_t * priv, chain_t * chain, const GUID* ppin_category)
1306 grabber_ringbuffer_t * pbuf,
1307 AM_MEDIA_TYPE ** arpmt,
1308 AM_MEDIA_TYPE* pmt, const GUID* ppin_category)
1309 { 1306 {
1310 HRESULT hr; 1307 HRESULT hr;
1311 int nFormatProbed = 0; 1308 int nFormatProbed = 0;
1312 1309
1313 IPin *pSGIn; 1310 IPin *pSGIn;
1321 ISampleGrabber *pSG = NULL; 1318 ISampleGrabber *pSG = NULL;
1322 1319
1323 hr=S_OK; 1320 hr=S_OK;
1324 1321
1325 //No supported formats 1322 //No supported formats
1326 if(!arpmt[0]) 1323 if(!chain->arpmt[0])
1327 return E_FAIL; 1324 return E_FAIL;
1328 1325
1329 do{ 1326 do{
1330 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin, 1327 hr = OLE_CALL_ARGS(priv->pBuilder, FindPin,
1331 (IUnknown *) pCaptureFilter, 1328 (IUnknown *) chain->pCaptureFilter,
1332 PINDIR_OUTPUT, ppin_category, 1329 PINDIR_OUTPUT, ppin_category,
1333 &(arpmt[nFormatProbed]->majortype), FALSE, 0, &pCapturePin); 1330 chain->majortype, FALSE, 0, &pCapturePin);
1334 if(FAILED(hr)){ 1331 if(FAILED(hr)){
1335 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: FindPin(pCapturePin) call failed. Error:0x%x\n", (unsigned int)hr); 1332 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: FindPin(pCapturePin) call failed. Error:0x%x\n", (unsigned int)hr);
1336 break; 1333 break;
1337 } 1334 }
1338 /* Addinf SampleGrabber filter for video stream */ 1335 /* Addinf SampleGrabber filter for video stream */
1356 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGOut) call failed. Error:0x%x\n", (unsigned int)hr); 1353 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: FindPin(pSGOut) call failed. Error:0x%x\n", (unsigned int)hr);
1357 break; 1354 break;
1358 } 1355 }
1359 1356
1360 /* creating ringbuffer for video samples */ 1357 /* creating ringbuffer for video samples */
1361 priv->pCSGCB = CSampleGrabberCB_Create(pbuf); 1358 priv->pCSGCB = CSampleGrabberCB_Create(chain->rbuf);
1362 if(!priv->pCSGCB){ 1359 if(!priv->pCSGCB){
1363 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CSampleGrabberCB_Create(pbuf) call failed. Error:0x%x\n", (unsigned int)E_OUTOFMEMORY); 1360 mp_msg(MSGT_TV,MSGL_DBG2, "tvi_dshow: CSampleGrabberCB_Create(pbuf) call failed. Error:0x%x\n", (unsigned int)E_OUTOFMEMORY);
1364 break; 1361 break;
1365 } 1362 }
1366 1363
1385 hr = OLE_CALL_ARGS(pSG, SetBufferSamples, FALSE); //... do not buffer samples in sample grabber 1382 hr = OLE_CALL_ARGS(pSG, SetBufferSamples, FALSE); //... do not buffer samples in sample grabber
1386 if(FAILED(hr)){ 1383 if(FAILED(hr)){
1387 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetBufferSamples(pSG) call failed. Error:0x%x\n", (unsigned int)hr); 1384 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetBufferSamples(pSG) call failed. Error:0x%x\n", (unsigned int)hr);
1388 break; 1385 break;
1389 } 1386 }
1390 if(priv->tv_param->normalize_audio_chunks && !memcmp(&(arpmt[nFormatProbed]->majortype),&(MEDIATYPE_Audio),16)){ 1387
1391 set_buffer_preference(20,(WAVEFORMATEX*)(arpmt[nFormatProbed]->pbFormat),pCapturePin,pSGIn); 1388 if(priv->tv_param->normalize_audio_chunks && chain->type==audio){
1392 } 1389 set_buffer_preference(20,(WAVEFORMATEX*)(chain->arpmt[nFormatProbed]->pbFormat),pCapturePin,pSGIn);
1393 1390 }
1394 for(nFormatProbed=0; arpmt[nFormatProbed]; nFormatProbed++) 1391
1392 for(nFormatProbed=0; chain->arpmt[nFormatProbed]; nFormatProbed++)
1395 { 1393 {
1396 DisplayMediaType("Probing format", arpmt[nFormatProbed]); 1394 DisplayMediaType("Probing format", chain->arpmt[nFormatProbed]);
1397 hr = OLE_CALL_ARGS(pSG, SetMediaType, arpmt[nFormatProbed]); //set desired mediatype 1395 hr = OLE_CALL_ARGS(pSG, SetMediaType, chain->arpmt[nFormatProbed]); //set desired mediatype
1398 if(FAILED(hr)){ 1396 if(FAILED(hr)){
1399 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetMediaType(pSG) call failed. Error:0x%x\n", (unsigned int)hr); 1397 mp_msg(MSGT_TV,MSGL_DBG2,"tvi_dshow: SetMediaType(pSG) call failed. Error:0x%x\n", (unsigned int)hr);
1400 continue; 1398 continue;
1401 } 1399 }
1402 /* connecting filters together: VideoCapture --> SampleGrabber */ 1400 /* connecting filters together: VideoCapture --> SampleGrabber */
1407 } 1405 }
1408 break; 1406 break;
1409 } 1407 }
1410 OLE_RELEASE_SAFE(pSG); 1408 OLE_RELEASE_SAFE(pSG);
1411 1409
1412 if(!arpmt[nFormatProbed]) 1410 if(!chain->arpmt[nFormatProbed])
1413 { 1411 {
1414 mp_msg(MSGT_TV, MSGL_WARN, "tvi_dshow: Unable to negotiate media format\n"); 1412 mp_msg(MSGT_TV, MSGL_WARN, "tvi_dshow: Unable to negotiate media format\n");
1415 hr = E_FAIL; 1413 hr = E_FAIL;
1416 break; 1414 break;
1417 } 1415 }
1418 1416
1419 hr = OLE_CALL_ARGS(pCapturePin, ConnectionMediaType, pmt); 1417 hr = OLE_CALL_ARGS(pCapturePin, ConnectionMediaType, chain->pmt);
1420 if(FAILED(hr)) 1418 if(FAILED(hr))
1421 { 1419 {
1422 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_GetActualMediatypeFailed, (unsigned int)hr); 1420 mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TVI_DS_GetActualMediatypeFailed, (unsigned int)hr);
1423 } 1421 }
1424 1422
2454 } else { 2452 } else {
2455 priv->chains[0]->rbuf->buffersize = 16; 2453 priv->chains[0]->rbuf->buffersize = 16;
2456 } 2454 }
2457 2455
2458 priv->chains[0]->rbuf->buffersize *= 1024 * 1024; 2456 priv->chains[0]->rbuf->buffersize *= 1024 * 1024;
2459 hr=build_sub_graph(priv, priv->chains[0]->pCaptureFilter, priv->chains[0]->rbuf, priv->chains[0]->arpmt, priv->chains[0]->pmt, &PIN_CATEGORY_CAPTURE); 2457 hr=build_sub_graph(priv, priv->chains[0], &PIN_CATEGORY_CAPTURE);
2460 if(FAILED(hr)){ 2458 if(FAILED(hr)){
2461 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVideoSubGraph,(unsigned int)hr); 2459 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVideoSubGraph,(unsigned int)hr);
2462 return hr; 2460 return hr;
2463 } 2461 }
2464 return S_OK; 2462 return S_OK;
2497 priv->chains[1]->rbuf->buffersize=audio_buf_size_from_video( 2495 priv->chains[1]->rbuf->buffersize=audio_buf_size_from_video(
2498 priv->chains[0]->rbuf->buffersize, 2496 priv->chains[0]->rbuf->buffersize,
2499 (((VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat)->dwBitRate), 2497 (((VIDEOINFOHEADER *) priv->chains[0]->pmt->pbFormat)->dwBitRate),
2500 (((WAVEFORMATEX *) (priv->chains[1]->pmt->pbFormat))->nAvgBytesPerSec)); 2498 (((WAVEFORMATEX *) (priv->chains[1]->pmt->pbFormat))->nAvgBytesPerSec));
2501 2499
2502 hr=build_sub_graph(priv, priv->chains[1]->pCaptureFilter, priv->chains[1]->rbuf,priv->chains[1]->arpmt,priv->chains[1]->pmt,&PIN_CATEGORY_CAPTURE); 2500 hr=build_sub_graph(priv, priv->chains[1],&PIN_CATEGORY_CAPTURE);
2503 if(FAILED(hr)){ 2501 if(FAILED(hr)){
2504 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildAudioSubGraph,(unsigned int)hr); 2502 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildAudioSubGraph,(unsigned int)hr);
2505 return 0; 2503 return 0;
2506 } 2504 }
2507 } 2505 }
2528 if(!priv->chains[2]->rbuf) 2526 if(!priv->chains[2]->rbuf)
2529 return E_OUTOFMEMORY; 2527 return E_OUTOFMEMORY;
2530 2528
2531 init_ringbuffer(priv->chains[2]->rbuf,24,priv->tsp.bufsize); 2529 init_ringbuffer(priv->chains[2]->rbuf,24,priv->tsp.bufsize);
2532 2530
2533 hr=build_sub_graph(priv, priv->chains[0]->pCaptureFilter, priv->chains[2]->rbuf,priv->chains[2]->arpmt,NULL,&PIN_CATEGORY_VBI); 2531 hr=build_sub_graph(priv, priv->chains[2],&PIN_CATEGORY_VBI);
2534 if(FAILED(hr)){ 2532 if(FAILED(hr)){
2535 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVBISubGraph,(unsigned int)hr); 2533 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TVI_DS_UnableBuildVBISubGraph,(unsigned int)hr);
2536 return 0; 2534 return 0;
2537 } 2535 }
2538 } 2536 }