Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: examples/thumb.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/sendtr.c ('k') | examples/tracks.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * \file thumb.c 2 * \file thumb.c
3 * Example program to send and associate album art to an entity 3 * Example program to send and associate album art to an entity
4 * on a device. 4 * on a device.
5 * 5 *
6 * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com> 6 * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 int main (int argc, char **argv) { 42 int main (int argc, char **argv) {
43 int opt; 43 int opt;
44 extern int optind; 44 extern int optind;
45 extern char *optarg; 45 extern char *optarg;
46 LIBMTP_mtpdevice_t *device = NULL; 46 LIBMTP_mtpdevice_t *device = NULL;
47 int fd; 47 int fd;
48 uint32_t id = 0; 48 uint32_t id = 0;
49 uint64_t filesize; 49 uint64_t filesize;
50 char *imagedata = NULL; 50 uint8_t *imagedata = NULL;
51 char *path = NULL; 51 char *path = NULL;
52 char *rest; 52 char *rest;
53 struct stat statbuff; 53 struct stat statbuff;
54 int ret; 54 int ret;
55 55
56 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 56 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
57 57
58 while ( (opt = getopt(argc, argv, "hi:")) != -1 ) { 58 while ( (opt = getopt(argc, argv, "hi:")) != -1 ) {
59 switch (opt) { 59 switch (opt) {
60 case 'h': 60 case 'h':
(...skipping 13 matching lines...) Expand all
74 usage(); 74 usage();
75 } 75 }
76 76
77 path = argv[0]; 77 path = argv[0];
78 78
79 if ( stat(path, &statbuff) == -1 ) { 79 if ( stat(path, &statbuff) == -1 ) {
80 fprintf(stderr, "%s: ", path); 80 fprintf(stderr, "%s: ", path);
81 perror("stat"); 81 perror("stat");
82 exit(1); 82 exit(1);
83 } 83 }
84 filesize = statbuff.st_size; 84 filesize = (uint64_t) statbuff.st_size;
85 imagedata = malloc(filesize); 85 imagedata = malloc(filesize * sizeof(uint16_t));
86 86
87 #ifdef __WIN32__ 87 #ifdef __WIN32__
88 if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { 88 if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
89 #else 89 #else
90 if ( (fd = open(path, O_RDONLY)) == -1) { 90 if ( (fd = open(path, O_RDONLY)) == -1) {
91 #endif 91 #endif
92 printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); 92 printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
93 return 1; 93 return 1;
94 } else { 94 }
95 ret = read(fd, imagedata, filesize); 95 else {
96 if (ret == -1) perror("read thumb data"); 96 read(fd, imagedata, filesize);
97 close(fd); 97 close(fd);
98 } 98 }
99 99
100 LIBMTP_Init(); 100 LIBMTP_Init();
101 device = LIBMTP_Get_First_Device(); 101 device = LIBMTP_Get_First_Device();
102 if (device == NULL) { 102 if (device == NULL) {
103 printf("No devices.\n"); 103 printf("No devices.\n");
104 return 0; 104 return 0;
105 } 105 }
106 106
107 LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t(); 107 LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
108 thumb->data = imagedata; 108
109 int i;
110 thumb->data = malloc(sizeof(uint16_t) * filesize);
111 for (i = 0; i < filesize; i++) {
112 thumb->data[i] = imagedata[i];
113 }
114
109 thumb->size = filesize; 115 thumb->size = filesize;
110 thumb->filetype = LIBMTP_FILETYPE_JPEG; 116 thumb->filetype = LIBMTP_FILETYPE_JPEG;
117
111 ret = LIBMTP_Send_Representative_Sample(device,id,thumb); 118 ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
112 if (ret != 0) { 119 if (ret != 0) {
113 printf("Couldn't send thumbnail\n"); 120 printf("Couldn't send thumbnail\n");
114 LIBMTP_Dump_Errorstack(device); 121 LIBMTP_Dump_Errorstack(device);
115 LIBMTP_Clear_Errorstack(device); 122 LIBMTP_Clear_Errorstack(device);
116 } 123 }
117 124
125 free(imagedata);
118 LIBMTP_destroy_filesampledata_t(thumb); 126 LIBMTP_destroy_filesampledata_t(thumb);
119 127
120 LIBMTP_Release_Device(device); 128 LIBMTP_Release_Device(device);
121 printf("OK.\n"); 129 printf("OK.\n");
122 return 0; 130 return 0;
123 } 131 }
OLDNEW
« no previous file with comments | « examples/sendtr.c ('k') | examples/tracks.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698