comparison data/fileio/MP3FileReader.cpp @ 1342:c0fece5e7755 3.0-integration

Improved debug output for file open troubleshooting
author Chris Cannam
date Fri, 06 Jan 2017 09:43:40 +0000
parents 47768571681e
children c380e56c95f5
comparison
equal deleted inserted replaced
1341:513e4d67d8df 1342:c0fece5e7755
75 CodedAudioFileReader::setFramesToTrim(DEFAULT_DECODER_DELAY, 0); 75 CodedAudioFileReader::setFramesToTrim(DEFAULT_DECODER_DELAY, 0);
76 } 76 }
77 77
78 struct stat stat; 78 struct stat stat;
79 if (::stat(m_path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { 79 if (::stat(m_path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) {
80 m_error = QString("File %1 does not exist.").arg(m_path); 80 m_error = QString("File %1 does not exist.").arg(m_path);
81 return; 81 SVDEBUG << "MP3FileReader: " << m_error << endl;
82 return;
82 } 83 }
83 84
84 m_fileSize = stat.st_size; 85 m_fileSize = stat.st_size;
85 86
86 m_fileBuffer = 0; 87 m_fileBuffer = 0;
93 if ((fd = ::open(m_path.toLocal8Bit().data(), O_RDONLY 94 if ((fd = ::open(m_path.toLocal8Bit().data(), O_RDONLY
94 #ifdef _WIN32 95 #ifdef _WIN32
95 | O_BINARY 96 | O_BINARY
96 #endif 97 #endif
97 , 0)) < 0) { 98 , 0)) < 0) {
98 m_error = QString("Failed to open file %1 for reading.").arg(m_path); 99 m_error = QString("Failed to open file %1 for reading.").arg(m_path);
99 return; 100 SVDEBUG << "MP3FileReader: " << m_error << endl;
101 return;
100 } 102 }
101 103
102 try { 104 try {
103 // We need a mysterious MAD_BUFFER_GUARD (== 8) zero bytes at 105 // We need a mysterious MAD_BUFFER_GUARD (== 8) zero bytes at
104 // end of input, to ensure libmad decodes the last frame 106 // end of input, to ensure libmad decodes the last frame
106 m_fileBufferSize = m_fileSize + MAD_BUFFER_GUARD; 108 m_fileBufferSize = m_fileSize + MAD_BUFFER_GUARD;
107 m_fileBuffer = new unsigned char[m_fileBufferSize]; 109 m_fileBuffer = new unsigned char[m_fileBufferSize];
108 memset(m_fileBuffer + m_fileSize, 0, MAD_BUFFER_GUARD); 110 memset(m_fileBuffer + m_fileSize, 0, MAD_BUFFER_GUARD);
109 } catch (...) { 111 } catch (...) {
110 m_error = QString("Out of memory"); 112 m_error = QString("Out of memory");
113 SVDEBUG << "MP3FileReader: " << m_error << endl;
111 ::close(fd); 114 ::close(fd);
112 return; 115 return;
113 } 116 }
114 117
115 ssize_t sz = 0; 118 ssize_t sz = 0;
116 ssize_t offset = 0; 119 ssize_t offset = 0;
117 while (offset < m_fileSize) { 120 while (offset < m_fileSize) {
119 if (sz < 0) { 122 if (sz < 0) {
120 m_error = QString("Read error for file %1 (after %2 bytes)") 123 m_error = QString("Read error for file %1 (after %2 bytes)")
121 .arg(m_path).arg(offset); 124 .arg(m_path).arg(offset);
122 delete[] m_fileBuffer; 125 delete[] m_fileBuffer;
123 ::close(fd); 126 ::close(fd);
127 SVDEBUG << "MP3FileReader: " << m_error << endl;
124 return; 128 return;
125 } else if (sz == 0) { 129 } else if (sz == 0) {
126 SVCERR << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes") 130 SVCERR << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes")
127 .arg(offset).arg(m_fileSize) << endl; 131 .arg(offset).arg(m_fileSize) << endl;
128 m_fileSize = offset; 132 m_fileSize = offset;