@@ -68,7 +68,7 @@ class videoStitcherTest extends TestCase
6868 private static $ updatedAkamaiTokenKey = 'VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg== ' ;
6969
7070 private static $ inputBucketName = 'cloud-samples-data ' ;
71- private static $ inputVideoFileName = '/media/hls-vod/manifest.m3u8 ' ;
71+ private static $ inputVodFileName = '/media/hls-vod/manifest.m3u8 ' ;
7272 private static $ vodUri ;
7373 private static $ vodAgTagUri = 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/vmap_ad_samples&sz=640x480&cust_params=sample_ar%3Dpreonly&ciu_szs=300x250%2C728x90&gdfp_req=1&ad_rule=1&output=vmap&unviewed_position_start=1&env=vp&impl=s&correlator= ' ;
7474
@@ -79,6 +79,14 @@ class videoStitcherTest extends TestCase
7979 private static $ vodStitchDetailId ;
8080 private static $ vodStitchDetailName ;
8181
82+ private static $ inputLiveFileName = '/media/hls-live/manifest.m3u8 ' ;
83+ private static $ liveUri ;
84+ private static $ liveAgTagUri = 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator= ' ;
85+ private static $ liveSessionId ;
86+ private static $ liveSessionName ;
87+ private static $ liveAdTagDetailId ;
88+ private static $ liveAdTagDetailName ;
89+
8290 public static function setUpBeforeClass (): void
8391 {
8492 self ::checkProjectEnvVars ();
@@ -90,7 +98,9 @@ public static function setUpBeforeClass(): void
9098 self ::$ slateUri = sprintf ('https://storage.googleapis.com/%s%s ' , self ::$ bucket , self ::$ slateFileName );
9199 self ::$ updatedSlateUri = sprintf ('https://storage.googleapis.com/%s%s ' , self ::$ bucket , self ::$ updatedSlateFileName );
92100
93- self ::$ vodUri = sprintf ('https://storage.googleapis.com/%s%s ' , self ::$ inputBucketName , self ::$ inputVideoFileName );
101+ self ::$ vodUri = sprintf ('https://storage.googleapis.com/%s%s ' , self ::$ inputBucketName , self ::$ inputVodFileName );
102+
103+ self ::$ liveUri = sprintf ('https://storage.googleapis.com/%s%s ' , self ::$ inputBucketName , self ::$ inputLiveFileName );
94104 }
95105
96106 public function testCreateSlate ()
@@ -430,6 +440,104 @@ public function testGetVodStitchDetail()
430440 $ this ->assertStringContainsString (self ::$ vodStitchDetailName , $ output );
431441 }
432442
443+ public function testCreateLiveSession ()
444+ {
445+ # Create a temporary slate for the live session (required)
446+ $ tempSlateId = sprintf ('php-test-slate-%s-%s ' , uniqid (), time ());
447+ $ this ->runFunctionSnippet ('create_slate ' , [
448+ self ::$ projectId ,
449+ self ::$ location ,
450+ $ tempSlateId ,
451+ self ::$ slateUri
452+ ]);
453+
454+ # API returns project number rather than project ID so
455+ # don't include that in $liveSessionName since we don't have it
456+ self ::$ liveSessionName = sprintf ('/locations/%s/liveSessions/ ' , self ::$ location );
457+
458+ $ output = $ this ->runFunctionSnippet ('create_live_session ' , [
459+ self ::$ projectId ,
460+ self ::$ location ,
461+ self ::$ liveUri ,
462+ self ::$ liveAgTagUri ,
463+ $ tempSlateId
464+ ]);
465+ $ this ->assertStringContainsString (self ::$ liveSessionName , $ output );
466+ self ::$ liveSessionId = explode ('/ ' , $ output );
467+ self ::$ liveSessionId = trim (self ::$ liveSessionId [(count (self ::$ liveSessionId ) - 1 )]);
468+ self ::$ liveSessionName = sprintf ('/locations/%s/liveSessions/%s ' , self ::$ location , self ::$ liveSessionId );
469+
470+ # Delete the temporary slate
471+ $ this ->runFunctionSnippet ('delete_slate ' , [
472+ self ::$ projectId ,
473+ self ::$ location ,
474+ $ tempSlateId
475+ ]);
476+ }
477+
478+ /** @depends testCreateLiveSession */
479+ public function testGetLiveSession ()
480+ {
481+ $ output = $ this ->runFunctionSnippet ('get_live_session ' , [
482+ self ::$ projectId ,
483+ self ::$ location ,
484+ self ::$ liveSessionId
485+ ]);
486+ $ this ->assertStringContainsString (self ::$ liveSessionName , $ output );
487+ }
488+
489+ /** @depends testGetLiveSession */
490+ public function testListLiveAdTagDetails ()
491+ {
492+ # To get ad tag details, you need to curl the main manifest and
493+ # a rendition first. This supplies media player information to the API.
494+ #
495+ # Curl the playUri first. The last line of the response will contain a
496+ # renditions location. Curl the live session name with the rendition
497+ # location appended.
498+
499+ $ stitcherClient = new VideoStitcherServiceClient ();
500+ $ formattedName = $ stitcherClient ->liveSessionName (self ::$ projectId , self ::$ location , self ::$ liveSessionId );
501+ $ session = $ stitcherClient ->getLiveSession ($ formattedName );
502+ $ playUri = $ session ->getPlayUri ();
503+
504+ $ manifest = file_get_contents ($ playUri );
505+ $ tmp = explode ("\n" , trim ($ manifest ));
506+ $ renditions = $ tmp [count ($ tmp ) - 1 ];
507+
508+ # playUri will be in the following format:
509+ # https://videostitcher.googleapis.com/v1/projects/{project}/locations/{location}/liveSessions/{session-id}/manifest.m3u8?signature=...
510+ # Replace manifest.m3u8?signature=... with the renditions location.
511+
512+ $ tmp = explode ('/ ' , $ playUri );
513+ array_pop ($ tmp );
514+ $ renditionsUri = sprintf ('%s/%s ' , join ('/ ' , $ tmp ), $ renditions );
515+ file_get_contents ($ renditionsUri );
516+
517+ self ::$ liveAdTagDetailName = sprintf ('/locations/%s/liveSessions/%s/liveAdTagDetails/ ' , self ::$ location , self ::$ liveSessionId );
518+ $ output = $ this ->runFunctionSnippet ('list_live_ad_tag_details ' , [
519+ self ::$ projectId ,
520+ self ::$ location ,
521+ self ::$ liveSessionId
522+ ]);
523+ $ this ->assertStringContainsString (self ::$ liveAdTagDetailName , $ output );
524+ self ::$ liveAdTagDetailId = explode ('/ ' , $ output );
525+ self ::$ liveAdTagDetailId = trim (self ::$ liveAdTagDetailId [(count (self ::$ liveAdTagDetailId ) - 1 )]);
526+ self ::$ liveAdTagDetailName = sprintf ('/locations/%s/liveSessions/%s/liveAdTagDetails/%s ' , self ::$ location , self ::$ liveSessionId , self ::$ liveAdTagDetailId );
527+ }
528+
529+ /** @depends testListLiveAdTagDetails */
530+ public function testGetLiveAdTagDetail ()
531+ {
532+ $ output = $ this ->runFunctionSnippet ('get_live_ad_tag_detail ' , [
533+ self ::$ projectId ,
534+ self ::$ location ,
535+ self ::$ liveSessionId ,
536+ self ::$ liveAdTagDetailId
537+ ]);
538+ $ this ->assertStringContainsString (self ::$ liveAdTagDetailName , $ output );
539+ }
540+
433541 private static function deleteOldSlates (): void
434542 {
435543 $ stitcherClient = new VideoStitcherServiceClient ();
0 commit comments