001: /*
002: * VideoStream.java
003: *
004: * ===========================================================================
005: */
006: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
007: * Copyright 2006 Laszlo Systems, Inc. All Rights Reserved. *
008: * Use is subject to license terms. *
009: * J_LZ_COPYRIGHT_END *********************************************************/
010: package org.openlaszlo.iv.flash.api.sound;
011:
012: import java.io.PrintStream;
013: import org.openlaszlo.iv.flash.util.*;
014: import org.openlaszlo.iv.flash.parser.*;
015: import org.openlaszlo.iv.flash.api.*;
016: import org.openlaszlo.iv.flash.api.action.*;
017:
018: public class VideoStream extends FlashDef {
019:
020: int width;
021: int height;
022: int codec;
023: int framecount = 0;
024:
025: int smoothing = 1;
026: int deblocking = 0;
027:
028: public int reserved; // 5 bits ( reserved, always 0 )
029:
030: int DEFAULTWIDTH = 160; // pixels
031: int DEFAULTHEIGHT = 120;
032: int DEFAULTCODEC = 0;
033:
034: public VideoStream(int width, int height) {
035: this .width = width;
036: this .height = height;
037: }
038:
039: public VideoStream(int width, int height, int codec) {
040: this .width = width;
041: this .height = height;
042: this .codec = codec;
043: }
044:
045: public VideoStream() {
046: this .width = DEFAULTWIDTH;
047: this .height = DEFAULTHEIGHT;
048: this .height = DEFAULTCODEC;
049: }
050:
051: public int getTag() {
052: return Tag.DEFINEVIDEOSTEAM;
053: }
054:
055: /* This tag defines a video stream. To playback the video stream, one needs to add a list of VideoFrame tags.
056:
057: struct swf_definevideostream
058: swf_tag f_tag;
059: unsigned short f_id;
060: unsigned short f_frame_count;
061: unsigned short f_width;
062: unsigned short f_height;
063: unsigned char f_reserved : 5;
064: unsigned char f_deblocking : 2;
065: unsigned char f_smoothing : 1;
066: unsigned char f_codec;
067:
068: */
069:
070: private int tagcode; // tag of this obj
071:
072: public static VideoStream parse(Parser p) {
073: VideoStream o = new VideoStream();
074:
075: o.tagcode = p.getTagCode();
076: o.setID(p.getUWord());
077: o.framecount = p.getUWord();
078: o.width = p.getUWord();
079: o.height = p.getUWord();
080: p.initBits();
081: o.reserved = p.getBits(5); // reserved
082: o.deblocking = p.getBits(2);
083: o.smoothing = p.getBits(1);
084: o.codec = p.getByte();
085: return o;
086: }
087:
088: public void write(FlashOutput fob) {
089: fob.writeTag(getTag(), 10);
090: //fob.skip(6);
091: fob.writeDefID(this );
092: fob.writeWord(framecount); // frame count = 0
093: fob.writeWord(width); // width
094: fob.writeWord(height); // height
095: fob.initBits(); // Prepare to write to bit buffer
096:
097: //fob.writeBits( 0, 5 ); // Reserved
098: fob.writeBits(reserved, 5);
099: fob.writeBits(deblocking, 2);
100: fob.writeBits(smoothing, 1);
101: fob.flushBits(); // End of first byte
102: fob.writeByte(codec); // codec
103: }
104:
105: public boolean isConstant() {
106: return true;
107: }
108:
109: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
110: super .copyInto(item, copier);
111:
112: ((VideoStream) item).tagcode = tagcode;
113: ((VideoStream) item).width = width;
114: ((VideoStream) item).height = height;
115: ((VideoStream) item).deblocking = deblocking;
116: ((VideoStream) item).smoothing = smoothing;
117: ((VideoStream) item).framecount = framecount;
118: ((VideoStream) item).codec = codec;
119:
120: return item;
121: }
122:
123: public FlashItem getCopy(ScriptCopier copier) {
124: return copyInto(new VideoStream(), copier);
125: }
126:
127: public void printContent(PrintStream out, String indent) {
128: if (getTag() == Tag.DEFINEVIDEOSTEAM) {
129: out.println(indent + "VideoStream");
130: } else {
131: out.println(indent + "VideoStream!");
132: }
133:
134: out.println(indent + " width: " + width);
135: out.println(indent + " height: " + height);
136: out.println(indent + " codec: " + codec);
137:
138: out.println(indent + " frame count: " + framecount);
139: out.println(indent + " smoothing: " + smoothing);
140: out.println(indent + " deblocking: " + deblocking);
141: }
142:
143: }
|