/* this method and saveFrame() won't be called concurrently,
so non-atomic on volatile is safe
191438
private int releaseTailFrame(ByteBuf content) {
    int frameSize = content.readableBytes();
    cacheSize -= frameSize;
    position += frameSize;
    content.release();
    return frameSize;
  }
916604
function init(){

    frameUnixTime = utils.getUnixTimeInMilliseconds();
    frameDuration = 0;
    frameDurationClone = 0;
    timeSinceStart = 0;
    playTimeSinceStart = 0;
    appActive = true;
    appPlaying = true;
    videoDuration = 0;
    videoPlaying = false;

}
588786
private void updateReversing(double extrp)
    {
        current -= speed * extrp;

        // First frame reached, done
        if (Double.compare(current, first) <= 0)
        {
            current = first;

            if (repeat)
            {
                state = AnimState.PLAYING;
                current += 1.0;
            }
            else
            {
                state = AnimState.FINISHED;
            }
        }
    }
835071
function FrameDecoder() {
  stream.Transform.call(this, {readableObjectMode: true});
  this._id = undefined;
  this._buf = utils.newBuffer(0);
  this._bufs = [];

  this.on('finish', function () { this.push(null); });
}
97015
function( /* arguments */ ) {
			gui.Tick.cancelFrame(this._frameindex);
			if (this.loaded) {
				if (!this.$input || this.$input.done) {
					if (this.spirit.life.entered) {
						this.write(this._run.apply(this, arguments));
					} else {
						this.spirit.life.add(gui.LIFE_ENTER, this);
						this._arguments = arguments;
					}
				} else {
					this._notready();
				}
			} else {
				this._notloaded();
			}
		}
158592
public void restart() {
		if (frames.size() == 0) {
			return;
		}
		stopped = false;
		currentFrame = 0;
		nextChange = (int) (((Frame) frames.get(0)).duration / speed);
		firstUpdate = true;
		lastUpdate = 0;
	}
157674
public void renderFrame(int frameNumber, Bitmap bitmap) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC);

    // If blending is required, prepare the canvas with the nearest cached frame.
    int nextIndex;
    if (!isKeyFrame(frameNumber)) {
      // Blending is required. nextIndex points to the next index to render onto the canvas.
      nextIndex = prepareCanvasWithClosestCachedFrame(frameNumber - 1, canvas);
    } else {
      // Blending isn't required. Start at the frame we're trying to render.
      nextIndex = frameNumber;
    }

    // Iterate from nextIndex to the frame number just preceding the one we're trying to render
    // and composite them in order according to the Disposal Method.
    for (int index = nextIndex; index < frameNumber; index++) {
      AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(index);
      DisposalMethod disposalMethod = frameInfo.disposalMethod;
      if (disposalMethod == DisposalMethod.DISPOSE_TO_PREVIOUS) {
        continue;
      }
      if (frameInfo.blendOperation == BlendOperation.NO_BLEND) {
        disposeToBackground(canvas, frameInfo);
      }
      mAnimatedDrawableBackend.renderFrame(index, canvas);
      mCallback.onIntermediateResult(index, bitmap);
      if (disposalMethod == DisposalMethod.DISPOSE_TO_BACKGROUND) {
        disposeToBackground(canvas, frameInfo);
      }
    }

    AnimatedDrawableFrameInfo frameInfo = mAnimatedDrawableBackend.getFrameInfo(frameNumber);
    if (frameInfo.blendOperation == BlendOperation.NO_BLEND) {
      disposeToBackground(canvas, frameInfo);
    }
    // Finally, we render the current frame. We don't dispose it.
    mAnimatedDrawableBackend.renderFrame(frameNumber, canvas);
  }
232719
public void onDrawFrame(float frameTime)
    {
        if (isEnabled() && (mScene != null) && mPickEventLock.tryLock())
        {
            // Don't call if we are in the middle of processing another pick
            try
            {
                doPick();
            }
            finally
            {
                mPickEventLock.unlock();
            }
        }
    }
1366786
private boolean writeFrameSync() throws FlowControlException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "writeFrameSync entry: stream: " + myID);
        }
        Frame currentFrame = this.currentFrame;

        if (!currentFrame.getFrameType().equals(FrameTypes.GOAWAY) && isStreamClosed()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "writeFrameSync exit - stream " + myID + " is closed");
            }
            return false;
        }
        if (currentFrame.isWriteFrame() && currentFrame.getInitialized()) {
            WsByteBuffer writeFrameBuffer = null;
            WsByteBuffer[] writeFrameBuffers = null;
            try {
                if (currentFrame.getFrameType() == FrameTypes.DATA) {
                    FrameData data = (FrameData) currentFrame;
                    boolean timedOut = false;

                    // Check to see if the write window is large enough to write this data.
                    if (isWindowLimitExceeded((FrameData) currentFrame)) {
                        // the connection or stream window is too small to write this data frame.  This thread will wait for a max of
                        // 5 seconds for a window update that's large enough to allow the data frame to be written out
                        long startTime = System.currentTimeMillis();
                        while (isWindowLimitExceeded((FrameData) currentFrame) && !timedOut) {
                            synchronized (this) {
                                this.wait(MAX_TIME_TO_WAIT_FOR_WINDOW_UPDATE_MS);
                            }
                            if (state.equals(StreamState.CLOSED) || muxLink.checkIfGoAwaySendingOrClosing()) {
                                return false;
                            } else if (System.currentTimeMillis() - startTime > MAX_TIME_TO_WAIT_FOR_WINDOW_UPDATE_MS) {
                                timedOut = true;
                            }
                        }
                    }
                    // the flow control window is large enough to write the data frame
                    if (!timedOut) {
                        writeFrameBuffers = data.buildFrameArrayForWrite();
                        muxLink.writeSync(null, writeFrameBuffers, data.getWriteFrameLength(), TCPRequestContext.NO_TIMEOUT,
                                          data.getFrameType(), data.getPayloadLength(), myID);

                        streamWindowUpdateWriteLimit -= currentFrame.getPayloadLength();
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "stream: " + myID + " Data payload written - new streamWindowUpdateWriteLimit: " + streamWindowUpdateWriteLimit);
                        }

                    } else {
                        // timed out waiting for a window update, throw FCE which will cause this stream to be RESET.
                        FlowControlException up = new FlowControlException("Write failed. Window limit exceeded. Stream will be Reset.");
                        up.setConnectionError(false);
                        throw up;
                    }

                } else {
                    // this frame is not a data frame, and so it's not subject to flow control and we can write immediately
                    writeFrameBuffer = currentFrame.buildFrameForWrite();
                    muxLink.writeSync(writeFrameBuffer, null, currentFrame.getWriteFrameLength(), TCPRequestContext.NO_TIMEOUT,
                                      currentFrame.getFrameType(), currentFrame.getPayloadLength(), myID);
                }
            } catch (IOException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "writeFrameSync caught an IOException: " + e);
                }

            } catch (InterruptedException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "writeFrameSync interrupted: " + e);
                }
            } finally {
                // release buffer used to synchronously write the frame
                if (writeFrameBuffer != null) {
                    writeFrameBuffer.release();
                } else if (writeFrameBuffers != null) {
                    for (int i = 0; i < writeFrameBuffers.length; i++) {
                        if (writeFrameBuffers[i] != null) {
                            // buffer at [1] is allocated by old channel code, it will clean it up
                            // later move this logic to a frame cleanup method that can take care of releasing
                            if (i != 1) {
                                writeFrameBuffers[i].release();
                            }
                        }
                    }
                }
            }

        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "writeFrameSync internal flow issue - exiting method ");
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "writeFrameSync exit: stream-id: " + myID);
        }
        return true;
    }
111547
public void writeFrame(byte[] frame) throws IOException {
        lastUsedTime = System.currentTimeMillis();
        out.write(frame);
        out.flush();
    }
879116
function() {
			gui.Tick.cancelFrame(this._frameindex);
			var spirit = this.spirit;
			var input = this.$input;
			var runnow = function() {
				if (!spirit.life.destructed && (!input || input.done)) {
					this.run();
				}
			}.bind(this);
			if (spirit.life.entered) {
				if (spirit.life.rendered) {
					this._frameindex = gui.Tick.nextFrame(runnow);
				} else {
					runnow();
				}
			} else {
				spirit.life.add(gui.LIFE_ENTER, this);
			}
		}
164434
synchronized void sync()
    {
        try
        {
            // check we have more work to do
            if (allocatePosition.get() <= lastSyncedOffset + SYNC_MARKER_SIZE)
                return;

            // allocate a new sync marker; this is both necessary in itself, but also serves to demarcate
            // the point at which we can safely consider records to have been completely written to
            int nextMarker;
            nextMarker = allocate(SYNC_MARKER_SIZE);
            boolean close = false;
            if (nextMarker < 0)
            {
                // ensure no more of this CLS is writeable, and mark ourselves for closing
                discardUnusedTail();
                close = true;

                // wait for modifications guards both discardedTailFrom, and any outstanding appends
                waitForModifications();

                if (discardedTailFrom < buffer.capacity() - SYNC_MARKER_SIZE)
                {
                    // if there's room in the discard section to write an empty header, use that as the nextMarker
                    nextMarker = discardedTailFrom;
                }
                else
                {
                    // not enough space left in the buffer, so mark the next sync marker as the EOF position
                    nextMarker = buffer.capacity();
                }
            }
            else
            {
                waitForModifications();
            }

            assert nextMarker > lastSyncedOffset;

            // write previous sync marker to point to next sync marker
            // we don't chain the crcs here to ensure this method is idempotent if it fails
            int offset = lastSyncedOffset;
            final PureJavaCrc32 crc = new PureJavaCrc32();
            crc.updateInt((int) (id & 0xFFFFFFFFL));
            crc.updateInt((int) (id >>> 32));
            crc.updateInt(offset);
            buffer.putInt(offset, nextMarker);
            buffer.putInt(offset + 4, crc.getCrc());

            // zero out the next sync marker so replayer can cleanly exit
            if (nextMarker < buffer.capacity())
            {
                buffer.putInt(nextMarker, 0);
                buffer.putInt(nextMarker + 4, 0);
            }

            // actually perform the sync and signal those waiting for it
            buffer.force();

            if (close)
                nextMarker = buffer.capacity();

            lastSyncedOffset = nextMarker;
            syncComplete.signalAll();

            CLibrary.trySkipCache(fd, offset, nextMarker);
            if (close)
                internalClose();
        }
        catch (Exception e) // MappedByteBuffer.force() does not declare IOException but can actually throw it
        {
            throw new FSWriteError(e, getPath());
        }
    }
48251
@Override
    public void doFrame(long timestampNanoseconds) {
        long frameIntervalNanoseconds = timestampNanoseconds - lastTimestampNanoseconds;

        // To detect a dropped frame, we need to know the interval between two frame callbacks.
        // If this is the first, wait for the second.
        if (lastTimestampNanoseconds != NEVER) {
            // With no dropped frames, frame intervals will roughly equal the hardware interval.
            // 2x the hardware interval means we definitely dropped one frame.
            // So our measuring stick is 1.5x.
            double droppedFrameIntervalSeconds = hardwareFrameIntervalSeconds * 1.5;

            double frameIntervalSeconds = frameIntervalNanoseconds / 1_000_000_000.0;

            if (droppedFrameIntervalSeconds < frameIntervalSeconds) {
                playTickSound();

                if (areHapticsEnabled) {
                    playTickHaptics();
                }
            }
        }

        lastTimestampNanoseconds = timestampNanoseconds;
        Choreographer.getInstance().postFrameCallback(this);
    }
793746
function () {
            var pos = this._savedX, newValue = Math.max(pos / this._railWidth, 0);
            if (newValue !== this._value) {
                this._value = newValue;
                this._storeValue();
            } else {
                this._notifyDataChange();
            }
            return;
        }
866737
@Override
  public void close() {
    if (!isClosed()) {
      closed = true;
      // With the current code we don't expect readableBytes > 0 to be possible here, added
      // defensively to prevent buffer leak issues if the framer code changes later.
      if (buffer != null && buffer.readableBytes() == 0) {
        releaseBuffer();
      }
      commitToSink(true, true);
    }
  }
1145836
@Override
	public synchronized boolean fireEventAndWait(Eventable eventable)
			throws ElementNotVisibleException, NoSuchElementException, InterruptedException {
		try {

			boolean handleChanged = false;
			boolean result = false;

			if (eventable.getRelatedFrame() != null && !eventable.getRelatedFrame().equals("")) {
				LOGGER.debug("switching to frame: " + eventable.getRelatedFrame());
				try {

					switchToFrame(eventable.getRelatedFrame());
				} catch (NoSuchFrameException e) {
					LOGGER.debug("Frame not found, possibly while back-tracking..", e);
					// TODO Stefan, This exception is caught to prevent stopping
					// from working
					// This was the case on the Gmail case; find out if not switching
					// (catching)
					// Results in good performance...
				}
				handleChanged = true;
			}

			WebElement webElement =
					browser.findElement(eventable.getIdentification().getWebDriverBy());

			if (webElement != null) {
				result = fireEventWait(webElement, eventable);
			}

			if (handleChanged) {
				browser.switchTo().defaultContent();
			}
			return result;
		} catch (ElementNotVisibleException | NoSuchElementException e) {
			throw e;
		} catch (WebDriverException e) {
			throwIfConnectionException(e);
			return false;
		}
	}
145706
private void handleFrameAvailable(SurfaceTexture surfaceTexture) {
        if (TRACE) Trace.beginSection("handleFrameAvail");
        synchronized (mReadyForFrameFence) {
            if (!mReadyForFrames) {
                if (VERBOSE) Log.i(TAG, "Ignoring available frame, not ready");
                return;
            }
            mFrameNum++;
            if (VERBOSE && (mFrameNum % 30 == 0)) Log.i(TAG, "handleFrameAvailable");
            if (!surfaceTexture.equals(mSurfaceTexture))
                Log.w(TAG, "SurfaceTexture from OnFrameAvailable does not match saved SurfaceTexture!");

            if (mRecording) {
                mInputWindowSurface.makeCurrent();
                if (TRACE) Trace.beginSection("drainVEncoder");
                mVideoEncoder.drainEncoder(false);
                if (TRACE) Trace.endSection();
                if (mCurrentFilter != mNewFilter) {
                    Filters.updateFilter(mFullScreen, mNewFilter);
                    mCurrentFilter = mNewFilter;
                    mIncomingSizeUpdated = true;
                }

                if (mIncomingSizeUpdated) {
                    mFullScreen.getProgram().setTexSize(mSessionConfig.getVideoWidth(), mSessionConfig.getVideoHeight());
                    mIncomingSizeUpdated = false;
                }

                surfaceTexture.getTransformMatrix(mTransform);
                if (TRACE) Trace.beginSection("drawVEncoderFrame");
                mFullScreen.drawFrame(mTextureId, mTransform);
                if (TRACE) Trace.endSection();
                if (!mEncodedFirstFrame) {
                    mEncodedFirstFrame = true;
                }

                if (mThumbnailRequestedOnFrame == mFrameNum) {
                    mThumbnailRequested = true;
                }
                if (mThumbnailRequested) {
                    saveFrameAsImage();
                    mThumbnailRequested = false;
                }

                mInputWindowSurface.setPresentationTime(mSurfaceTexture.getTimestamp());
                mInputWindowSurface.swapBuffers();

                if (mEosRequested) {
                    /*if (VERBOSE) */
                    Log.i(TAG, "Sending last video frame. Draining encoder");
                    mVideoEncoder.signalEndOfStream();
                    mVideoEncoder.drainEncoder(true);
                    mRecording = false;
                    mEosRequested = false;
                    releaseEncoder();
                    mState = STATE.UNINITIALIZED;
                    synchronized (mStopFence) {
                        mStopFence.notify();
                    }
                }
            }
        }

        // Signal GLSurfaceView to render
        mDisplayView.requestRender();

        if (TRACE) Trace.endSection();
    }