/** * Try to match all the tracks and find common formats to concatenate the tracks. A database of * results will be generated. */ public boolean matchTracks(ProcInfo pInfo[], ContentDescriptor cd) { TrackControl tcs[]; // Vector<String> aTracks; // Vector<String> vTracks; int aIdx, vIdx; int i, j, type; TrackInfo tInfo; // Build the ProcInfo data structure for each processor. // Sparate out the audio from video tracks. for (i = 0; i < pInfo.length; i++) { if (!waitForState(pInfo[i].p, Processor.Configured)) { System.err.println("- Failed to configure the processor."); return false; } tcs = pInfo[i].p.getTrackControls(); pInfo[i].tracksByType = new TrackInfo[MEDIA_TYPES][]; for (type = AUDIO; type < MEDIA_TYPES; type++) { pInfo[i].tracksByType[type] = new TrackInfo[tcs.length]; } pInfo[i].numTracksByType = new int[MEDIA_TYPES]; aIdx = vIdx = 0; // Separate the audio and video tracks. for (j = 0; j < tcs.length; j++) { if (tcs[j].getFormat() instanceof AudioFormat) { tInfo = new TrackInfo(); tInfo.idx = j; tInfo.tc = tcs[j]; pInfo[i].tracksByType[AUDIO][aIdx++] = tInfo; } else if (tcs[j].getFormat() instanceof VideoFormat) { tInfo = new TrackInfo(); tInfo.idx = j; tInfo.tc = tcs[j]; pInfo[i].tracksByType[VIDEO][vIdx++] = tInfo; } } pInfo[i].numTracksByType[AUDIO] = aIdx; pInfo[i].numTracksByType[VIDEO] = vIdx; pInfo[i].p.setContentDescriptor(cd); } // Different movies has different number of tracks. Obviously, // we cannot concatenate all the tracks of 3-track movie with a // 2-track one. We'll concatenate up to the smallest # of tracks // of all the movies. We'll also need to disable the unused tracks. int total[] = new int[MEDIA_TYPES]; for (type = AUDIO; type < MEDIA_TYPES; type++) { total[type] = pInfo[0].numTracksByType[type]; } for (i = 1; i < pInfo.length; i++) { for (type = AUDIO; type < MEDIA_TYPES; type++) { if (pInfo[i].numTracksByType[type] < total[type]) total[type] = pInfo[i].numTracksByType[type]; } } if (total[AUDIO] < 1 && total[VIDEO] < 1) { System.err.println("There is no audio or video tracks to concatenate."); return false; } totalTracks = 0; for (type = AUDIO; type < MEDIA_TYPES; type++) totalTracks += total[type]; // Disable all the unused tracks. for (i = 0; i < pInfo.length; i++) { for (type = AUDIO; type < MEDIA_TYPES; type++) { for (j = total[type]; j < pInfo[i].numTracksByType[type]; j++) { tInfo = pInfo[i].tracksByType[type][j]; disableTrack(pInfo[i], tInfo); System.err.println( "- Disable the following track since the other input media do not have a matching type."); System.err.println(" " + tInfo.tc.getFormat()); } pInfo[i].numTracksByType[type] = total[type]; } } // Try to find common formats to concatenate the tracks. // Deal with the tracks by type. for (type = AUDIO; type < MEDIA_TYPES; type++) { for (i = 0; i < total[type]; i++) { if (!tryMatch(pInfo, type, i)) { System.err.println( "- Cannot transcode the tracks to a common format for concatenation! Sorry."); return false; } } } return true; }