Skip to main content

How to create the instance of ClosedCaptionControl

7 replies [Last post]
sdyavarashetti
Offline
Joined: 2010-07-27
Points: 0

Hi members,

I have the video which is having closed captioning and i need to enable it through the application.So i have used the following code:

import javax.tv.service.selection.ServiceContentHandler;
import javax.tv.service.selection.ServiceContext;
import javax.tv.service.selection.ServiceContextFactory;
import javax.media.Player;
import org.ocap.media.ClosedCaptioningControl;

private ClosedCaptioningControl mCcControl = null;
private Player mPlayer = null;

private ServiceContext mSc;

private ServiceContextFactory mScf;

mScf = ServiceContextFactory.getInstance();

try {

mSc = mScf.createServiceContext();

} catch (InsufficientResourcesException e) {

fail("testSetUp" + e.getMessage());

}

ServiceContentHandler[] mSch = mSc.getServiceContentHandlers();

mPlayer = (Player) mSch[0];

mCcControl = (ClosedCaptioningControl) mPlayer.getControl("org.ocap.media.ClosedCaptioningControl");

Here, using this mCcControl instance we can enable ccing using

mCcControl.setClosedCaptioningState(ClosedCaptioningControl.CC_TURN_ON);

but when i print the above values

mScf------->org.cablelabs.impl.service.javatv.selection.ServiceContextFactoryImpl@4d97a194

mSc------->org.cablelabs.impl.service.javatv.selection.DVRServiceContextImpl@c9e93801

mSch.length------->0, so it is failing because the lenght is 0 and it fails to create the player instance and closed caption control instance.

So can anyone please tell me how to solve this issue?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ramks
Offline
Joined: 2010-06-17
Points: 0

You have to do a service selection to get a player.
ServiceContext.select(Service).

Only if you present something (video), you can do something with CC for that Service.

One more thing, wait for NormalContentEvent before querying for the player.
ServiceContext.addListener(ServiceContextListener).

sdyavarashetti
Offline
Joined: 2010-07-27
Points: 0

Hi ramks,

Can u please provide me the code.

Actually, i tried with:

service = javax.tv.service.SIManager.createInstance().getService(new org.ocap.net.OcapLocator(16380));

//Here 16380 is the source id of the channel which has the Closed Caption Text

System.out.println("service-->>>>>>>>>>>>>>>:"+service);
mSc.select(service);
ServiceContentHandler[] scHandler = mSc.getServiceContentHandlers();
System.out.println("scHandler[]:"+scHandler.length);
mPlayer = (Player) scHandler[0];
System.out.println("mPlayer:"+mPlayer);
mCcControl = (ClosedCaptioningControl) mPlayer.getControl("org.ocap.media.ClosedCaptioningControl");
System.out.println("mCcControl:"+mCcControl);

But the length -- scHandler.length, i am getting is 0.

So please help me in solvinf this issue.

ramks
Offline
Joined: 2010-06-17
Points: 0

As I said eariler, you have to wait for NormalContentEvent.
ServiceContext.addListener(ServiceContextListener listener).

You will get a player only if ServiceContext in presenting state.

sdyavarashetti
Offline
Joined: 2010-07-27
Points: 0

Hi Ramks,

As u said, i have written like:

mScf = ServiceContextFactory.getInstance();
ServiceContextListenerMock eventMock = new ServiceContextListenerMock();
try {
mSc = mScf.createServiceContext();
} catch (InsufficientResourcesException e) {
fail("testSetUp" + e.getMessage());
}

DbFilter filter = DatabaseFactory.createDbFilter( DbFilter . TYPE_SERVICES );
System.out.println("filter:"+filter);
DbIterator serviceIterator = DatabaseFactory.createDbIterator(filter, 20);
System.out.println("serviceIterator:"+serviceIterator);

try {
int count = 0;
int counter = 0;
while (serviceIterator.hasNext() && counter == 0) {
count++;
ServiceElement service = (ServiceElement) serviceIterator.next();

mSc.addListener(eventMock);
mSc.select(service);
synchronized (eventMock) {
try{
System.out.println("Inside try block>>>>>>>>>>>>>>>>>>>>>");
eventMock.wait(MAX_WAIT);
System.out.println("After Wait>>>>>>>>>>>>>>>>>>>>>");
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
mSc.removeListener(eventMock);
ServiceContentHandler scHandler[] = mSc.getServiceContentHandlers();
System.out.println("scHandler[]:"+scHandler.length);

for (int i = 0; i < scHandler.length; i++) {
if (scHandler[i] instanceof Controller) {
Controller controller = (Controller) scHandler[i];
Control control[] = controller.getControls();
for (int j = 0; j < control.length; j++) {
if (control[j] instanceof ClosedCaptioningControl) {
System.out.println("Found ClosedCaptioningControl " + control[j]);
counter++;
}
}
}
}
}

----
public static class ServiceContextListenerMock implements ServiceContextListener {
public Object event = null;
public void receiveServiceContextEvent(ServiceContextEvent arg0) {
synchronized(this) {
event = arg0;
this.notifyAll();
}
}
}

But it is throwing the below exception:

20100802 09:47:02.218 INFO RI.Stack.StdOut- (JVM stdout) Inside try block>>>>>>>>>>>>>>>>>>>>>
20100802 09:47:02.218 INFO RI.Stack- 45531 [System-1] INFO selection.ServiceContextImpl - select called in NOT PRESENTING: (id b48fb04f, NOT_PRESENTING, no delegate)
20100802 09:47:02.218 INFO RI.Stack- 45532 [System-1] INFO selection.ServiceContextImpl - setting state to PRESENTING_PENDING: (id b48fb04f, NOT_PRESENTING, no delegate)
20100802 09:47:02.218 INFO RI.Stack- 45533 [System-1] INFO selection.ServiceContextImpl - calling delegate.present: (id b48fb04f, PRESENTING_PENDING, no delegate)
20100802 09:47:02.234 INFO RI.Stack- 45533 [System-1] INFO selection.DVRBroadcastServiceContextDelegate - present - new service: org.ocapx.impl.l.p@b90859cd, locators: null
20100802 09:47:02.234 INFO RI.Stack- 45537 [System-1] INFO application.AppExecQueue - Exception in AppExecQueue
20100802 09:47:02.234 INFO RI.Stack- java.lang.ClassCastException: org.ocapx..l.pimpl
at org.cablelabs.impl.manager.timeshift.TimeShiftWindow.(TimeShiftWindow.java:335)
at org.cablelabs.impl.manager.timeshift.TimeShiftManagerImpl$4.getBestTSW(TimeShiftManagerImpl.java:632)
at org.cablelabs.impl.manager.timeshift.TimeShiftManagerImpl.getTSWByEvaluation(TimeShiftManagerImpl.java:885)
at org.cablelabs.impl.manager.timeshift.TimeShiftManagerImpl.getTSWByDuration(TimeShiftManagerImpl.java:644)
at org.cablelabs.impl.service.javatv.selection.DVRBroadcastServiceContextDelegate.present(DVRBroadcastServiceContextDelegate.java:298)
at org.cablelabs.impl.service.javatv.selection.ServiceContextImpl.doSelect(ServiceContextImpl.java:1124)
at org.cablelabs.impl.service.javatv.selection.ServiceContextImpl.access$400(ServiceContextImpl.java:81)
at org.cablelabs.impl.service.javatv.selection.ServiceContextImpl$3.run(ServiceContextImpl.java:508)
at org.cablelabs.impl.manager.application.WorkerTask.run(WorkerTask.java:120)
at org.cablelabs.impl.manager.application.AppExecQueue$1.run(AppExecQueue.java:109)
at java.lang.Thread.run(Thread.java:715)
at java.lang.Thread.startup(Thread.java:785)
20100802 09:47:12.218 INFO RI.Stack.StdOut- (JVM stdout) After Wait>>>>>>>>>>>>>>>>>>>>>
20100802 09:47:12.218 INFO RI.Stack.StdOut- (JVM stdout) scHandler[]:0
20100802 09:47:12.218 INFO RI.Stack- 55519 [Thread-12] INFO selection.ServiceContextImpl - select service (PRESENTING_PENDING) - org.ocapx.impl.l.p@db92e1af: (id b48fb04f, PRESENTING_PENDING, delegate: DVRBroadcastServiceContextDelegate - service: null)
20100802 09:47:12.218 INFO RI.Stack.StdOut- (JVM stdout) Inside try block>>>>>>>>>>>>>>>>>>>>>
20100802 09:47:12.218 INFO RI.Stack- 55522 [System-1] INFO selection.ServiceContextImpl - select called in PRESENTING PENDING: (id b48fb04f, PRESENTING_PENDING, delegate: DVRBroadcastServiceContextDelegate - service: null)
20100802 09:47:12.218 INFO RI.Stack- 55523 [System-1] INFO selection.ServiceContextImpl - posting SelectionFailedEvent(interrupted): (id b48fb04f, PRESENTING_PENDING, delegate: DVRBroadcastServiceContextDelegate - service: null)
20100802 09:47:12.218 INFO RI.Stack- 55525 [System-1] INFO selection.ServiceContextImpl - setting state to NEW_SELECT_STOP_PENDING: (id b48fb04f, PRESENTING_PENDING, delegate: DVRBroadcastServiceContextDelegate - service: null)
20100802 09:47:12.218 INFO RI.Stack- 55526 [System-1] INFO selection.ServiceContextImpl - stopping delegate: (id b48fb04f, NEW_SELECT_STOP_PENDING, delegate: DVRBroadcastServiceContextDelegate - service: null)

cpratt
Offline
Joined: 2008-12-18
Points: 0

I'm not sure what "DatabaseFactory" is or what "ServiceElement" objects are, but they are apparently not stack-derived javax.tv.Service objects - which is causing the stack to throw an error attempting to cast them.

This code should work once you've supplied a Service object obtained via SIManager.getService(Locator locator) or SIManager.filterServices(ServiceFilter filter).

Have a look at org.cablelabs.xlet.TuneTest for an example of how to implement simple service selection.

sdyavarashetti
Offline
Joined: 2010-07-27
Points: 0

In order to enable cc, we need to implement the ServiceContextListener and need to wait for the NormalContentEvent and we need to get the instance of Player and then using player instance we can get the cc instance.I have got the cc instance and i got the cc status as TURN_OFF (default value 1) and i set the value to TURN_ON i.e. 0, however it is throwing some exception.

Please find the following implemented code to enable the cc:

mScf = ServiceContextFactory.getInstance();
try {

mSc = mScf.createServiceContext();

} catch (InsufficientResourcesException e) {

fail("testSetUp" + e.getMessage());

}

Service service = null;

mSc.addListener(this);

SIManager sManager = SIManager.createInstance();

try {

service = sManager.getService(new org.ocap.net.OcapLocator(11678)); -- here passed the source id which is having cc text.

System.out.println("testSetUp():service----->>>>>>>>>>>"+service);

}

catch(Exception e){

}

mPlayer = null;

mSc.select(service);

waitServiceContextEvent();

System.out.println("testSetUp():mPlayer----->>>>>>>>>>>"+mPlayer); -- testSetUp():mPlayer----->>>>>>>>>>>TSBServiceMediaHandler@3c1d233a

mCcControl = (ClosedCaptioningControl) mPlayer.getControl("org.ocap.media.ClosedCaptioningControl");

System.out.println("testSetUp():mCcControl----->>>>>>>>>>>"+mCcControl); -- testSetUp():mCcControl----->>>>>>>>>>>org.cablelabs.impl.media.player.AbstractServicePlayer$ClosedCaptioningControlImpl@741226da

final int mState = mCcControl.getClosedCaptioningState();

System.out.println("testSetUp():mState----->>>>>>>>>>>"+mState); -- testSetUp():mState----->>>>>>>>>>>0

if (mState == ClosedCaptioningControl.CC_TURN_OFF) {

mCcControl.setClosedCaptioningState(ClosedCaptioningControl.CC_TURN_ON); -- here it is throwing exception as -- RI.Stack- ERROR in jniSetCCState: mpe_ccSetClosedCaptioning() = 102

}

System.out.println("testSetUp():after Change----->>>>>>>>>>>"+ mCcControl.getClosedCaptioningState());

mSc.stop();

waitServiceContextEvent();

mSc.removeListener(this);

mSc.destroy();

private void waitServiceContextEvent() {

synchronized (lockServiceContext) {

try {

lockServiceContext.wait(WAIT_TIME);

} catch (InterruptedException e) {

}

}

}

csweeney
Offline
Joined: 2009-04-11
Points: 0