Gets an array of sample numbers that are meant to be the first sample of each
chunk or fragment.

@param track concerned track
@return an array containing the ordinal of each fragment's first sample
487252
public long[] sampleNumbers(Track track) {

        if ("vide".equals(track.getHandler())) {
            if (track.getSyncSamples() != null && track.getSyncSamples().length > 0) {
                List<long[]> times = getSyncSamplesTimestamps(movie, track);
                return getCommonIndices(track.getSyncSamples(), getTimes(track, movie), track.getTrackMetaData().getTimescale(), times.toArray(new long[times.size()][]));
            } else {
                throw new RuntimeException("Video Tracks need sync samples. Only tracks other than video may have no sync samples.");
            }
        } else if ("soun".equals(track.getHandler())) {
            if (referenceTrack == null) {
                for (Track candidate : movie.getTracks()) {
                    if (candidate.getSyncSamples() != null && "vide".equals(candidate.getHandler()) && candidate.getSyncSamples().length > 0) {
                        referenceTrack = candidate;
                    }
                }
            }
            if (referenceTrack != null) {

                // Gets the reference track's fra
                long[] refSyncSamples = sampleNumbers(referenceTrack);

                int refSampleCount = referenceTrack.getSamples().size();

                long[] syncSamples = new long[refSyncSamples.length];
                long minSampleRate = 192000;
                for (Track testTrack : movie.getTracks()) {
                    if (getFormat(track).equals(getFormat(testTrack))) {
                        AudioSampleEntry ase = null;
                        for (SampleEntry sampleEntry : testTrack.getSampleEntries()) {
                            if (ase == null) {
                                ase = (AudioSampleEntry) sampleEntry;
                            } else if (ase.getSampleRate() != ((AudioSampleEntry) sampleEntry).getSampleRate()) {
                                throw new RuntimeException("Multiple SampleEntries and different sample rates is not supported");
                            }
                        }
                        assert ase != null;
                        if (ase.getSampleRate() < minSampleRate) {
                            minSampleRate = ase.getSampleRate();
                            long sc = testTrack.getSamples().size();
                            double stretch = (double) sc / refSampleCount;

                            long samplesPerFrame = testTrack.getSampleDurations()[0]; // Assuming all audio tracks have the same number of samples per frame, which they do for all known types

                            for (int i = 0; i < syncSamples.length; i++) {
                                long start = (long) Math.ceil(stretch * (refSyncSamples[i] - 1) * samplesPerFrame);
                                syncSamples[i] = start;
                                // The Stretch makes sure that there are as much audio and video chunks!
                            }
                            break;
                        }
                    }
                }
                AudioSampleEntry ase = null;
                for (SampleEntry sampleEntry : track.getSampleEntries()) {
                    if (ase == null) {
                        ase = (AudioSampleEntry) sampleEntry;
                    } else if (ase.getSampleRate() != ((AudioSampleEntry) sampleEntry).getSampleRate()) {
                        throw new RuntimeException("Multiple SampleEntries and different sample rates is not supported");
                    }
                }
                assert ase != null;

                long samplesPerFrame = track.getSampleDurations()[0]; // Assuming all audio tracks have the same number of samples per frame, which they do for all known types
                double factor = (double) ase.getSampleRate() / (double) minSampleRate;
                if (factor != Math.rint(factor)) { // Not an integer
                    throw new RuntimeException("Sample rates must be a multiple of the lowest sample rate to create a correct file!");
                }
                for (int i = 0; i < syncSamples.length; i++) {
                    syncSamples[i] = (long) (1 + syncSamples[i] * factor / (double) samplesPerFrame);
                }
                return syncSamples;
            }
            throw new RuntimeException("There was absolutely no Track with sync samples. I can't work with that!");
        } else {
            // Ok, my track has no sync samples - let's find one with sync samples.
            for (Track candidate : movie.getTracks()) {
                if (candidate.getSyncSamples() != null && candidate.getSyncSamples().length > 0) {
                    long[] refSyncSamples = sampleNumbers(candidate);
                    int refSampleCount = candidate.getSamples().size();

                    long[] syncSamples = new long[refSyncSamples.length];
                    long sc = track.getSamples().size();
                    double stretch = (double) sc / refSampleCount;

                    for (int i = 0; i < syncSamples.length; i++) {
                        long start = (long) Math.ceil(stretch * (refSyncSamples[i] - 1)) + 1;
                        syncSamples[i] = start;
                        // The Stretch makes sure that there are as much audio and video chunks!
                    }
                    return syncSamples;
                }
            }
            throw new RuntimeException("There was absolutely no Track with sync samples. I can't work with that!");
        }


    }
1092159
private void selectCandidateTracks() {
		// mark tracks in right frame that are active
		List<PointTrack> activeRight = trackerRight.getActiveTracks(null);
		for( PointTrack t : activeRight ) {
			RightTrackInfo info = t.getCookie();
			info.lastActiveList = tick;
		}

		int mutualActive = 0;
		List<PointTrack> activeLeft = trackerLeft.getActiveTracks(null);
		candidates.clear();
		for( PointTrack left : activeLeft ) {
			LeftTrackInfo info = left.getCookie();

//			if( info == null || info.right == null ) {
//				System.out.println("Oh Crap");
//			}

			// for each active left track, see if its right track has been marked as active
			RightTrackInfo infoRight = info.right.getCookie();
			if( infoRight.lastActiveList != tick ) {
				continue;
			}

			// check epipolar constraint and see if it is still valid
			if( stereoCheck.checkPixel(left, info.right) ) {
				info.lastConsistent = tick;
				candidates.add(left);
			}
			mutualActive++;
		}

//		System.out.println("Active Tracks: Left "+trackerLeft.getActiveTracks(null).size()+" right "+
//				trackerRight.getActiveTracks(null).size());
//		System.out.println("All Tracks:    Left "+trackerLeft.getAllTracks(null).size()+" right "+
//				trackerRight.getAllTracks(null).size());
//		System.out.println("Candidates = "+candidates.size()+" mutual active = "+mutualActive);
	}
65501
protected double[] firstHit(Instance inst) {
		boolean fired = false;
		int countFired = 0;
		double[] votes = new double[this.numClass];
		for (int j = 0; j < this.ruleSet.size(); j++) {
			if (this.ruleSet.get(j).ruleEvaluate(inst) == true) {
				countFired = countFired + 1;
				for (int z = 0; z < this.numClass; z++) {
					votes[z] = this.ruleSet.get(j).obserClassDistrib.getValue(z) 
							/ this.ruleSet.get(j).obserClassDistrib.sumOfValues();
					}
				return votes;
				}
			}
		if (countFired > 0) {
			fired = true;
			} else {
				fired = false;
				}
		if (fired == false) {
			votes = oberversDistribProb(inst, this.observedClassDistribution);
			}
		return votes;
		}
121822
def _sample_batch_prioritized(self, segment_tree, batch_size, history, forward_steps=1):
        
        p_total = segment_tree.total()
        segment = p_total / batch_size

        # Get batch of valid samples
        batch = [
            self._get_sample_from_segment(segment_tree, segment, i, history, forward_steps)
            for i in range(batch_size)
        ]

        probs, idxs, tree_idxs = zip(*batch)
        return np.array(probs), np.array(idxs), np.array(tree_idxs)
839851
private TrackSourceSlot findTrackSourceSlot() {
        TrackSourceSlot result = TRACK_SOURCE_SLOT_MAP.get(packetBytes[41]);
        if (result == null) {
            return TrackSourceSlot.UNKNOWN;
        }
        return result;
    }
506304
@Override
    public int first() {
        fCachedBreakPositions = null;
        fDictionaryCharCount = 0;
        fPositionInCache = 0;
        fLastRuleStatusIndex  = 0;
        fLastStatusIndexValid = true;
        if (fText == null) {
            return BreakIterator.DONE;
        }
        fText.first();
        return fText.getIndex();
    }
1075077
public SoundCloudTrack previous() {
        int tracks = mSoundCloudPlaylist.getTracks().size();
        mCurrentTrackIndex = (tracks + mCurrentTrackIndex - 1) % tracks;
        return mSoundCloudPlaylist.getTracks().get(mCurrentTrackIndex);
    }
869295
private TrackType findTrackType() {
        TrackType result = TRACK_TYPE_MAP.get(packetBytes[42]);
        if (result == null) {
            return TrackType.UNKNOWN;
        }
        return result;
    }
165207
public static List<long[]> getSyncSamplesTimestamps(Movie movie, Track track) {
        List<long[]> times = new LinkedList<long[]>();
        for (Track currentTrack : movie.getTracks()) {
            if (currentTrack.getHandler().equals(track.getHandler())) {
                long[] currentTrackSyncSamples = currentTrack.getSyncSamples();
                if (currentTrackSyncSamples != null && currentTrackSyncSamples.length > 0) {
                    final long[] currentTrackTimes = getTimes(currentTrack, movie);
                    times.add(currentTrackTimes);
                }
            }
        }
        return times;
    }
332846
private int dropUnusedTracks() {

		List<PointTrack> all = trackerLeft.getAllTracks(null);
		int num = 0;

		for( PointTrack t : all ) {
			LeftTrackInfo info = t.getCookie();
			if( tick - info.lastInlier > thresholdRetire ) {
				if( !trackerLeft.dropTrack(t) )
					throw new IllegalArgumentException("failed to drop unused left track");
				if( !trackerRight.dropTrack(info.right) )
					throw new IllegalArgumentException("failed to drop unused right track");
				num++;
			}
		}
//		System.out.println("  total unused dropped "+num);

		return num;
	}
272216
public SampleFormat[] getSupportedSampleFormats() {
		IntPointer sampleFormatsPointer = avCodec.sample_fmts();

		if (getType() != MediaType.AUDIO || sampleFormatsPointer == null)
			return null;

		List<SampleFormat> sampleFormats = new ArrayList<SampleFormat>();

		int format;
		int index = 0;
		while ((format = sampleFormatsPointer.get(index++)) != -1)
			sampleFormats.add(SampleFormat.byId(format));

		return sampleFormats.toArray(new SampleFormat[0]);
	}
1088884
public final double sampleCount()
  {
    synchronized (_lock) {
      long count = _count.get();
      long lastCount = _lastCount;
      _lastCount = count;

      return count - lastCount;
    }
  }
450984
private long getSafePts(long pts, int trackIndex) {
        if (mLastPts[trackIndex] >= pts) {
            // Enforce a non-zero minimum spacing
            // between pts
            mLastPts[trackIndex] += 9643;
            return mLastPts[trackIndex];
        }
        mLastPts[trackIndex] = pts;
        return pts;
    }
992663
function cacheTracksArray(self) {
  self.tracksInOrder = Object.keys(self.playlist).map(trackById);
  self.tracksInOrder.sort(asc);
  self.tracksInOrder.forEach(function(track, index) {
    track.index = index;
  });

  function asc(a, b) {
    return operatorCompare(a.sortKey, b.sortKey);
  }
  function trackById(id) {
    return self.playlist[id];
  }
}
905186
function getHeatmap(tracks) {
    var heatmap = [];
    _.each(tracks, function(track) {
        var idxStart = Math.floor(track.startTime / HEATMAP_SEGMENT), idxEnd = Math.ceil(track.endTime / HEATMAP_SEGMENT);
        idxEnd = Math.min(MAX_HEATMAP_LEN, idxEnd); /* Protection - sometimes we have buggy tracks which end in Infinity */

        for (var i=idxStart; i<idxEnd; i++) {
          if (i<0) continue;
          if (! heatmap[i]) heatmap[i] = 0;
          USE_BOOLEAN ? heatmap[i] = 1 : heatmap[i]++;
        }
    });

    /* Heatmap: Fill in the blanks */
    for (var i = 0; i!=heatmap.length; i++) 
      if (! heatmap[i]) heatmap[i] = 0;   

    return heatmap;
}
393132
function encodeTrack(track) {
    var events = track.getEvents(), data = [],
        length = events.length, i,
        runningStatus = null, result;

    for (i = 0; i < length; i += 1) {
        result = encodeEvent(events[i], runningStatus);
        runningStatus = result.runningStatus;

        data[i] = result.data;
    }

    return encodeChunk('MTrk', buffer.Buffer.concat(data));
}
208415
public long firstRecordSequenceNumber()
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "firstRecordSequenceNumber", this);
        if (tc.isEntryEnabled())
            Tr.exit(tc, "firstRecordSequenceNumber", new Long(_firstRecordSequenceNumber));
        return _firstRecordSequenceNumber;
    }