core: Make the `NetStream`/AVM link bidirectional
This commit is contained in:
parent
067474dea5
commit
da2ef5392e
|
@ -10,7 +10,7 @@ pub fn constructor<'gc>(
|
|||
this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let netstream = NetStream::new(activation.context.gc_context);
|
||||
let netstream = NetStream::new(activation.context.gc_context, Some(this.into()));
|
||||
this.set_native(
|
||||
activation.context.gc_context,
|
||||
NativeObject::NetStream(netstream),
|
||||
|
|
|
@ -15,15 +15,16 @@ pub fn netstream_allocator<'gc>(
|
|||
activation: &mut Activation<'_, 'gc>,
|
||||
) -> Result<Object<'gc>, Error<'gc>> {
|
||||
let base = ScriptObjectData::new(class);
|
||||
|
||||
Ok(NetStreamObject(GcCell::allocate(
|
||||
let ns = NetStream::new(activation.context.gc_context, None);
|
||||
let this: Object<'gc> = NetStreamObject(GcCell::allocate(
|
||||
activation.context.gc_context,
|
||||
NetStreamObjectData {
|
||||
base,
|
||||
ns: NetStream::new(activation.context.gc_context),
|
||||
},
|
||||
NetStreamObjectData { base, ns },
|
||||
))
|
||||
.into())
|
||||
.into();
|
||||
|
||||
ns.set_avm_object(activation.context.gc_context, this.into());
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
|
||||
#[derive(Clone, Collect, Copy)]
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::backend::navigator::Request;
|
|||
use crate::context::UpdateContext;
|
||||
use crate::loader::Error;
|
||||
use crate::string::AvmString;
|
||||
use crate::vminterface::AvmObject;
|
||||
use flv_rs::{
|
||||
AudioData as FlvAudioData, Error as FlvError, FlvReader, Header as FlvHeader,
|
||||
ScriptData as FlvScriptData, Tag as FlvTag, TagData as FlvTagData, Value as FlvValue,
|
||||
|
@ -107,7 +108,7 @@ impl<'gc> StreamManager<'gc> {
|
|||
/// is intended to be a VM-agnostic version of those.
|
||||
#[derive(Clone, Debug, Collect, Copy)]
|
||||
#[collect(no_drop)]
|
||||
pub struct NetStream<'gc>(GcCell<'gc, NetStreamData>);
|
||||
pub struct NetStream<'gc>(GcCell<'gc, NetStreamData<'gc>>);
|
||||
|
||||
impl<'gc> PartialEq for NetStream<'gc> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
|
@ -136,8 +137,8 @@ pub enum NetStreamType {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Collect)]
|
||||
#[collect(require_static)]
|
||||
pub struct NetStreamData {
|
||||
#[collect(no_drop)]
|
||||
pub struct NetStreamData<'gc> {
|
||||
/// All data currently loaded in the stream.
|
||||
buffer: Vec<u8>,
|
||||
|
||||
|
@ -167,10 +168,13 @@ pub struct NetStreamData {
|
|||
/// Any `Video`s on the stage will display the bitmap here when attached to
|
||||
/// this `NetStream`.
|
||||
last_decoded_bitmap: Option<BitmapInfo>,
|
||||
|
||||
/// The AVM side of this stream.
|
||||
avm_object: Option<AvmObject<'gc>>,
|
||||
}
|
||||
|
||||
impl<'gc> NetStream<'gc> {
|
||||
pub fn new(gc_context: MutationContext<'gc, '_>) -> Self {
|
||||
pub fn new(gc_context: MutationContext<'gc, '_>, avm_object: Option<AvmObject<'gc>>) -> Self {
|
||||
Self(GcCell::allocate(
|
||||
gc_context,
|
||||
NetStreamData {
|
||||
|
@ -180,10 +184,15 @@ impl<'gc> NetStream<'gc> {
|
|||
stream_type: None,
|
||||
stream_time: 0.0,
|
||||
last_decoded_bitmap: None,
|
||||
avm_object,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn set_avm_object(self, gc_context: MutationContext<'gc, '_>, avm_object: AvmObject<'gc>) {
|
||||
self.0.write(gc_context).avm_object = Some(avm_object);
|
||||
}
|
||||
|
||||
pub fn load_buffer(self, gc_context: MutationContext<'gc, '_>, data: &mut Vec<u8>) {
|
||||
self.0.write(gc_context).buffer.append(data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue