Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libjitsi
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ZRTP
libjitsi
Commits
c6c114e5
Commit
c6c114e5
authored
12 years ago
by
Lyubomir Marinov
Browse files
Options
Downloads
Patches
Plain Diff
Addresses a media- and UI-related freeze.
parent
a5be6c84
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/org/jitsi/impl/neomedia/protocol/CachingPushBufferStream.java
+97
-40
97 additions, 40 deletions
...jitsi/impl/neomedia/protocol/CachingPushBufferStream.java
with
97 additions
and
40 deletions
src/org/jitsi/impl/neomedia/protocol/CachingPushBufferStream.java
+
97
−
40
View file @
c6c114e5
...
...
@@ -252,7 +252,9 @@ public Object getControl(String controlType)
if
((
control
==
null
)
&&
BufferControl
.
class
.
getName
().
equals
(
controlType
))
{
control
=
getBufferControl
();
}
return
control
;
}
...
...
@@ -281,11 +283,13 @@ public Object[] getControls()
boolean
bufferControlExists
=
false
;
for
(
Object
control
:
controls
)
{
if
(
control
instanceof
BufferControl
)
{
bufferControlExists
=
true
;
break
;
}
}
if
(!
bufferControlExists
)
{
BufferControl
bufferControl
=
getBufferControl
();
...
...
@@ -378,11 +382,11 @@ public void read(Buffer buffer)
{
if
(
readException
!=
null
)
{
IOException
e
x
=
new
IOException
();
IOException
io
e
=
new
IOException
();
e
x
.
initCause
(
readException
);
io
e
.
initCause
(
readException
);
readException
=
null
;
throw
e
x
;
throw
io
e
;
}
buffer
.
setLength
(
0
);
...
...
@@ -553,30 +557,26 @@ private int read(Buffer input, Buffer output, int outputOffset)
*/
public
void
setTransferHandler
(
BufferTransferHandler
transferHandler
)
{
synchronized
(
cache
)
{
BufferTransferHandler
substituteTransferHandler
=
(
transferHandler
==
null
)
?
null
:
new
StreamSubstituteBufferTransferHandler
(
transferHandler
,
stream
,
this
)
BufferTransferHandler
substituteTransferHandler
=
(
transferHandler
==
null
)
?
null
:
new
StreamSubstituteBufferTransferHandler
(
transferHandler
,
stream
,
this
)
{
@Override
public
void
transferData
(
PushBufferStream
stream
)
{
@Override
public
void
transferData
(
PushBufferStream
stream
)
{
if
(
CachingPushBufferStream
.
this
.
stream
==
stream
)
{
CachingPushBufferStream
.
this
.
transferData
(
this
);
}
super
.
transferData
(
stream
);
}
};
if
(
CachingPushBufferStream
.
this
.
stream
==
stream
)
CachingPushBufferStream
.
this
.
transferData
(
this
);
super
.
transferData
(
stream
);
}
};
synchronized
(
cache
)
{
stream
.
setTransferHandler
(
substituteTransferHandler
);
this
.
transferHandler
=
substituteTransferHandler
;
cache
.
notifyAll
();
...
...
@@ -595,41 +595,98 @@ public void transferData(PushBufferStream stream)
*/
protected
void
transferData
(
BufferTransferHandler
transferHandler
)
{
/*
* Obviously, we cannot cache every Buffer because we will run out of
* memory. So wait for root to appear within cache (or for this instance
* to be stopped, of course).
*/
boolean
interrupted
=
false
;
boolean
canWriteInCache
=
false
;
synchronized
(
cache
)
{
boolean
interrupted
=
false
;
while
(
true
)
{
if
(
this
.
transferHandler
!=
transferHandler
)
return
;
if
(
canWriteInCache
())
{
/*
* The specified transferHandler has already been
* obsoleted/replaced so it does not have the right to cause
* a read or a write.
*/
canWriteInCache
=
false
;
break
;
try
}
else
if
(
canWriteInCache
())
{
cache
.
wait
();
canWriteInCache
=
true
;
break
;
}
catch
(
InterruptedException
iex
)
else
{
interrupted
=
true
;
try
{
cache
.
wait
(
DEFAULT_BUFFER_LENGTH
);
}
catch
(
InterruptedException
iex
)
{
interrupted
=
true
;
}
}
}
if
(
interrupted
)
Thread
.
currentThread
().
interrupt
();
}
if
(
interrupted
)
{
Thread
.
currentThread
().
interrupt
();
}
else
if
(
canWriteInCache
)
{
/*
* The protocol of PushBufferStream's #read(Buffer) method is that
* it does not block. The underlying implementation may be flawed
* though so we would better not take any chances. Besides, we have
* a report at the time of this writing which suggests that we may
* really be hitting a rogue implementation in a real-world
* scenario.
*/
Buffer
buffer
=
new
Buffer
();
IOException
readException
;
try
{
stream
.
read
(
buffer
);
readException
=
null
;
}
catch
(
IOException
ioex
)
catch
(
IOException
ioe
)
{
readException
=
ioe
;
}
if
(
readException
==
null
)
{
readException
=
ioex
;
if
(!
buffer
.
isDiscard
()
&&
(
buffer
.
getLength
()
!=
0
)
&&
(
buffer
.
getData
()
!=
null
))
{
/*
* Well, we risk disagreeing with #canWriteInCache() because
* we have temporarily released the cache but we have read a
* Buffer from the stream so it is probably better to not
* throw it away.
*/
synchronized
(
cache
)
{
cache
.
add
(
buffer
);
cacheLengthInMillis
+=
getLengthInMillis
(
buffer
);
}
}
}
else
{
synchronized
(
cache
)
{
this
.
readException
=
readException
;
}
}
cache
.
add
(
buffer
);
cacheLengthInMillis
+=
getLengthInMillis
(
buffer
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment