1/*! 2 * \copy 3 * Copyright (c) 2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33#define ENDLESS_LOOP //define to do the performance testing 34#define NO_OUTPUT_MODE //define to disable the output yuv file 35 36extern int DecMain(int argc, char * argv[]); 37 38#import "DEMOViewController.h" 39#import "DEMOViewControllerShowResource.h" 40 41@interface DEMOViewController () 42 43@end 44 45@implementation DEMOViewController 46 47- (void)viewDidLoad 48{ 49 [super viewDidLoad]; 50 // Do any additional setup after loading the view, typically from a nib. 51 //Add the testing codes 52 self.resFileArray = [[NSMutableArray alloc] init]; 53 self.selectedRow = 0; 54 [self updateResourceArray]; 55 //Init the status indication window 56 _statusIndication = [[UIAlertView alloc] initWithTitle: @"Decoding" message: @"Waiting the decoding" delegate: self cancelButtonTitle: @"Cancel" otherButtonTitles: nil]; 57 if ([self.resFileArray count] > self.selectedRow) 58 self.currentSelectedFileTF.text = [[self.resFileArray objectAtIndex:self.selectedRow] lastPathComponent]; 59} 60 61- (void)didReceiveMemoryWarning 62{ 63 [super didReceiveMemoryWarning]; 64 // Dispose of any resources that can be recreated. 65} 66 67- (IBAction)startDecoderAll:(id)sender { 68 bEnableFlag = YES; 69 [_statusIndication show]; 70 [NSThread detachNewThreadSelector:@selector(processDecoderAll) toTarget:self withObject:nil]; 71} 72 73- (IBAction)startDecoderOne:(id)sender { 74 bEnableFlag = YES; 75 [_statusIndication show]; 76 [NSThread detachNewThreadSelector:@selector(processDecoderOne) toTarget:self withObject:nil]; 77} 78- (void)processDecoderAll 79{ 80 [self updateResourceArray]; 81 if (YES == [self DoDecoderAll]) { 82 [self performSelectorOnMainThread:@selector(showAlertWnd) withObject:nil waitUntilDone:NO]; 83 } 84} 85- (void)processDecoderOne 86{ 87 if (YES == [self DoDecoderOne:self.selectedRow]) { 88 [self performSelectorOnMainThread:@selector(showAlertWnd) withObject:nil waitUntilDone:NO]; 89 } 90} 91 92- (void)showAlertWnd 93{ 94 [_statusIndication dismissWithClickedButtonIndex:0 animated:(BOOL)YES]; 95 [self showAlertWindowTitle:@"Successful" message: @"Decode is successful!"]; 96} 97 98-(void)showAlertWindowTitle:(NSString*)title message:(NSString*)message 99{ 100 UIAlertView *someError = [[UIAlertView alloc] initWithTitle: title message: message delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil]; 101 [someError show]; 102} 103 104//Delegate for alertView 105- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 106{ 107 if (_statusIndication == alertView) { 108 bEnableFlag = NO; 109 } 110} 111 112 113- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 114{ 115 if ([segue.identifier isEqualToString:@"segueShowResource"]) { 116 [self updateResourceArray]; 117 UINavigationController *navigationController = [segue destinationViewController]; 118 DEMOViewControllerShowResource *ViewControllerShowResource = (DEMOViewControllerShowResource *)[navigationController topViewController]; 119 ViewControllerShowResource.resFileArray = self.resFileArray; 120 } 121} 122 123//unwind segue 124- (void)unwindSegueForShowResourceViewController:(UIStoryboardSegue *)segue 125{ 126 DEMOViewControllerShowResource *ViewControllerShowResource = [segue sourceViewController]; 127 self.selectedRow = ViewControllerShowResource.selectedRow; 128 if ([self.resFileArray count] > self.selectedRow) 129 self.currentSelectedFileTF.text = [[self.resFileArray objectAtIndex:self.selectedRow] lastPathComponent]; 130} 131 132//**************************************************************************/ 133// Following codes is for demo testing input 134//**************************************************************************/ 135- (BOOL) DoDecoderAll 136{ 137 BOOL bResult; 138 for (NSUInteger index=0; index<[self.resFileArray count]; index++) { 139 if ((bResult = [self DoDecoderOne:index]) == NO) { 140 return NO; 141 } 142 } 143 return YES; 144} 145- (BOOL) DoDecoderOne:(NSUInteger)index 146{ 147 char *argv[3];//0 for exe name, 1 for resource input, 2 for output yuvfile 148 int argc = 3; 149 NSString *fileName = [[self.resFileArray objectAtIndex:index] lastPathComponent]; 150 NSString *outputFileName = [[fileName stringByDeletingPathExtension] stringByAppendingPathExtension:@"yuv"]; 151 NSString *outputFilePath = [[[self.resFileArray objectAtIndex:index] stringByDeletingLastPathComponent] stringByAppendingPathComponent:outputFileName]; 152 argv[0] = (char *)("decConsole.exe"); 153 argv[1] = (char *)[[self.resFileArray objectAtIndex:index] UTF8String]; //input resouce file path 154 argv[2] = (char *)[outputFilePath UTF8String]; //output file path 155 if (bEnableFlag == NO) { 156 return NO; 157 } 158 DecMain(argc, argv); 159 return YES; 160} 161 162- (void) updateResourceArray 163{ 164 //Clear the resource array 165 if ([self.resFileArray count] > 0) { 166 [self.resFileArray removeAllObjects]; 167 } 168 //get the sharing folder path 169 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 170 NSString *sharingFolderPath = [paths objectAtIndex:0]; 171 //enumerate the h.264 files at sharing folder 172 NSFileManager *fileManager = [NSFileManager defaultManager]; 173 174 NSError *error; 175 NSArray * directoryContents = [fileManager contentsOfDirectoryAtPath:sharingFolderPath error:&error]; 176 for (NSUInteger index=0; index < [directoryContents count]; index++) { 177 NSString *fileName = [directoryContents objectAtIndex:index]; 178 if (([fileName hasSuffix:@"264"] == YES) || 179 ([fileName hasSuffix:@"h264"] == YES)|| 180 ([fileName hasSuffix:@"H264"] == YES)) 181 { 182 [self.resFileArray addObject:[sharingFolderPath stringByAppendingPathComponent:fileName]]; 183 } 184 } 185} 186 187@end 188