27 import com.nokia.microedition.media.InputStreamSeekControl; |
27 import com.nokia.microedition.media.InputStreamSeekControl; |
28 import com.nokia.mj.impl.utils.Logger; |
28 import com.nokia.mj.impl.utils.Logger; |
29 |
29 |
30 public class SourceStreamReader extends Thread |
30 public class SourceStreamReader extends Thread |
31 { |
31 { |
32 Thread t1 = null; |
32 Thread t1 = null; |
33 // these states are the same in c++ side |
33 // these states are the same in c++ side |
34 private static final int NO_ERROR = 0; |
34 private static final int NO_ERROR = 0; |
35 private static final int ERR_GENERAL = -2; // KErrGeneral |
35 private static final int ERR_GENERAL = -2; // KErrGeneral |
36 private static final int ERR_EOF = -25; // KErrEof |
36 private static final int ERR_EOF = -25; // KErrEof |
37 private static final int READ_ALL = -1; |
37 private static final int READ_ALL = -1; |
93 public void run() |
93 public void run() |
94 { |
94 { |
95 int length = 0; |
95 int length = 0; |
96 do |
96 do |
97 { |
97 { |
98 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run()"); |
98 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run()"); |
99 iStatus = MORE_DATA; |
99 iStatus = MORE_DATA; |
100 try |
100 try |
101 { |
101 { |
102 length = iSourceStream.read(iBuffer, 0, iLength); |
102 length = iSourceStream.read(iBuffer, 0, iLength); |
103 } |
103 } |
104 catch (IOException ioe) |
104 catch (IOException ioe) |
105 { |
105 { |
106 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), io exception"); |
106 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), io exception"); |
107 ioe.printStackTrace(); |
107 ioe.printStackTrace(); |
108 iStatus = ERR_GENERAL; |
108 iStatus = ERR_GENERAL; |
109 } |
109 } |
110 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), length = "+length); |
110 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), length = "+length); |
111 if (iStatus == CLOSED) |
111 if (iStatus == CLOSED) |
112 { |
112 { |
113 return; |
113 return; |
114 } |
114 } |
115 // no more data because end of file has been reach |
115 // no more data because end of file has been reach |
116 if (length == -1) |
116 if (length == -1) |
117 { |
117 { |
118 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"no more data because end of file has been reach"); |
118 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"no more data because end of file has been reach"); |
119 iStatus = COMPLETED; |
119 iStatus = COMPLETED; |
120 } |
120 } |
121 // synchronized (iWaitObject) |
121 // synchronized (iWaitObject) |
122 // { |
122 // { |
123 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling jni _write"+"status =" + iStatus + "length =" + length); |
123 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling jni _write"+"status =" + iStatus + "length =" + length); |
124 |
124 |
125 int err = _write(iHandle, |
125 int err = _write(iHandle, |
126 iEventSourceHandle, |
126 iEventSourceHandle, |
127 iBuffer, |
127 iBuffer, |
128 length, |
128 length, |
129 iStatus, |
129 iStatus, |
130 iPlayerHandle); |
130 iPlayerHandle); |
131 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling jni _write ret = "+err); |
131 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling jni _write ret = "+err); |
132 if (err != 0) |
132 if (err != 0) |
133 { |
133 { |
134 // error in writing, closing thread |
134 // error in writing, closing thread |
135 iIsActive = false; |
135 iIsActive = false; |
136 iStatus = CLOSED; |
136 iStatus = CLOSED; |
137 break; |
137 break; |
138 } |
138 } |
139 // wait for next native read |
139 // wait for next native read |
140 // try |
140 // try |
141 // { |
141 // { |
142 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling wait()"); |
142 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling wait()"); |
143 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling wait() thread is =" +Thread.currentThread().getName()); |
143 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"Source stream reader run(), calling wait() thread is =" +Thread.currentThread().getName()); |
144 // iWaitObject.wait(); |
144 // iWaitObject.wait(); |
145 //} |
145 //} |
146 /*catch (InterruptedException ex) |
146 /*catch (InterruptedException ex) |
147 { |
147 { |
148 // MIDP's object does not have interrupt |
148 // MIDP's object does not have interrupt |
149 }*/ |
149 }*/ |
150 // } |
150 // } |
151 } |
151 } |
152 while (length>0); |
152 while (length>0); |
153 } |
153 } |
154 |
154 |
155 /** |
155 /** |
250 { |
250 { |
251 // notify to while() write -loop that data is requested |
251 // notify to while() write -loop that data is requested |
252 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader:: read() before sync(iWaitObjet() "); |
252 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader:: read() before sync(iWaitObjet() "); |
253 synchronized (iWaitObject) |
253 synchronized (iWaitObject) |
254 { |
254 { |
255 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader:: read() notifying iWaitObject"); |
255 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader:: read() notifying iWaitObject"); |
256 iWaitObject.notify(); |
256 iWaitObject.notify(); |
257 } |
257 } |
258 } |
258 } |
259 else |
259 else |
260 { |
260 { |
261 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader, creating new Thread"); |
261 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,"SourceStreamReader, creating new Thread"); |
262 iIsActive = true; |
262 iIsActive = true; |
263 t1 = new Thread(this); |
263 t1 = new Thread(this); |
264 t1.start(); |
264 t1.start(); |
265 // start(); |
265 // start(); |
266 } |
266 } |
267 |
267 |
268 } |
268 } |
269 |
269 |
270 |
270 |